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
DavidHabib.ax407DavidHabib.ax407 

fields in Contact object in Trigger are all null?

I'm trying to write my first trigger (on Contacts), and I'm finding that the Trigger.new collection of Contacts seem to only hold contact.Id, but all other fields of the contacts are null. 
 
Here's the code, and it asserts at c.Name != null.  All the other sample code I've looked at seem to reference fields of the objects in Trigger.new without any problems.  What am I doing wrong?
 
trigger ContactTrigger on Contact (after insert, after update) {

    for (Contact c:Trigger.new) {

        system.assert(c != null);

        system.assert(c.Id != null);

        system.assert(c.Name != null);

    }

}

SuperfellSuperfell
Name is a read-only compound field, and so isn't resolved until after a DB roundtrip, other regular fields on contact should be fine.
DavidHabib.ax407DavidHabib.ax407
I'm testing this on an update of an existing record.  I've also tried several other fields of existing records, like Account and Household (a custom field).  They all come back null.  No luck!
SuperfellSuperfell
only data fields that are directly part of the object are populated, fields from related objects (accessible via relationships, like account) are not, if you need the related data you need to query for it, using the FK ids (e,g. accountId)