function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Questions around Apex fundamentals: sObject, Id's, joining objects

1. Contact c = new Contact();

For the statement above is 'c' an instance of the class Contact hence making it an object of the class Contact? Is Contact (standard object) a class which salesforce refers to as sObjects?

2. t.WhatId =  ('t' is an instance of the standard object task and 'a' is an instance of the standard object Account)

2.1 Could you explain whats going on in the above statement? An example would be helpful.
My guess: In the statement above the record id of created account 'a' being associated with the new task created. The id (in the task object) is a foreign key linked to the account object. 

2.2  The Id fields dont seem to be listed as object fields when viewing the fields (customize objects>fields). Whats the best way to locate the id fields in sObjects. Is it via reports? Any alternatives?

3. c.AccountId = at.Account__c; The goal of this statement is to make the account in the attendee (at) object (lookup to account) appear in the newly created contact (c). See code below.

Why would these statements not work? :
c.Account = at.Account__c
c.AccountId = at.Account__cId (linking the Id's)

Refrence code which uses the above statements:
trigger CreateContact on Attendee__c (after insert, after update) {

List <Contact> contactToInsert = new List <Contact>();
for(Attendee__c at{

Contact c = new Contact();

c.Division__c = at.Division__c;

c.FirstName = at.First_Name__c;
c.LastName = at.Last_Name__c;
c.AccountId = at.Account__c;



insert contactToInsert;


trigger CreateFlowupTask on Account (after insert,after update) {

// Created collection for saving new tasks
List <task> taskToInsert = new List <task> ();

//Trigger new is the list of all new accounts

for (Account a : {
task t = new task ();
t.Subject = 'Call';
t.Status = 'Not Started';
t.Priority = 'Normal';

t.WhatId =;



insert taskToInsert;

Best Answer chosen by Forcedotcom737
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior

1 - Yes, c is an instance of sObject Contact. Every Standard or Custom object derives from the superclass sObject. The term sObject refers to any object that can be stored in the platform database. (" target="_blank)

2 - Yes and Yes.

2.1 - You are correct. WhatIds are polymorphic. Polymorphic means a WhatId is equivalent to the ID of a related object. WhatId is a polymorphic Lookup Field (foreign key). By associating a Account with a Task, you will able to see the Task in the related list Task in the Account Detail Page layout. (" target="_blank)

2.2 - Well if you want to query them you can use the developer console, which is a powerful online development tool, to query any sObject's field in a org. You can find on youtube tons of guides. (" target="_blank)

3. The field that relates the parent object with the child object in the child contains the parent id. For Contact, it's AccountId. For a custom object, it was set by the user creating the field. You can go to the child object and check. Once you know the field name, you can access it directly. For Contact:
Id parentId = myContact.AccountId;
For an object with a MasterDetail (or lookup) field called Parent__c:
Id parentId = myObject.Parent__c;
When retrieving data, using the suffix __c you get the Id of the target object in a relationship. 

Using the suffix __r you get the target object itself.

"[...]In addition, certain objects, including custom objects, have one or more fields of type reference that contain the ID value for a related record. These fields have names that end in the suffix “-Id”, for example, OwnerId in the account object. OwnerId contains the ID of the user who owns that object. Unlike the field named Id, reference fields are analogous to foreign keys and can be changed via the update() call. For more information, see Reference Field Type.[..]" (" target="_blank) (" target="_blank)


Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.