+ Start a Discussion
Jordan Miles 9Jordan Miles 9 

Including null values in Trigger.new

Is there a way to include null values in a Trigger.new record? It looks like the record only includes non-null. In an "after update" trigger, I post the data to an external system to be updated, and I need to know what fields have been removed. I haven't been able to find any information on this.

Thanks.
Thota Rakesh 1Thota Rakesh 1
Hi Jordan Miles 9,


Check this sample code and try to understand how to set Null values using Trigger.New

if statement in loop should be like below,
 
if (c.AccountId == a.Id) {
   if(a.Account_Manager__r.Id != NULL)
      c.OwnerId = a.Account_Manager__r.Id;
   else
      c.OwnerId = UserInfo.getUserId();
   break;
}


Best Regards,
Thota Rakesh.

 
Eric PepinEric Pepin
Trigger.New contains the trigger objects with all fields included, even the ones that are NULL. When you view query results, it only shows the populated fields, but all fields are available to the code. To show that this is the case, on any Trigger.New record, find one of the suspected NULLs and do a system.assertEquals(null, [sObject].[fieldName])....it should return TRUE.