+ Start a Discussion
ketan mehtaketan mehta 

Is it possible to check whether the record if modified in before update trigger?

Hi,
   I want to check if a record is modified before executing any operation on record in before update trigger. 


Regards,
Ketan
MikeGillMikeGill
Yes, this is possible. You have trigger.old and trigger old map available to you.

You can do something like this

trigger TriggerExample on Contact (before update) {

   for (Contact con: Trigger.new) {
        Contact oldContact = Trigger.oldMap.get(con.ID);
        if(con.Email != oldContact.Email) {
           System.debug('DEBUG Email Changing');
           
        }
        else{
          System.debug('DEBUG Email Not Changing');
            
        }
    }
}


AshlekhAshlekh
Hi,

In trigger  you can check the old vallue of field in the record and what is new value in the field for the record.

In update trigger you can get this by below code.

If you want list then use below code
List<YourObjectAPINAME> OldRecords = Trigger.old;
List<YourObjectAPINAME> newRecords = Trigger.new; 

If you want to get Map then use below code
MAP<Id,YourObjectAPINAME> OldRecords = Trigger.oldMap;
Map<Id,YourObjectAPINAME> newRecords = Trigger.newMap

Below link which help you when you get which vaialbe value in which event;

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables_considerations.htm

If it htelps you than please mark it as solution and ENJOY APEX.

Cloud_forceCloud_force
you can compare old and new values in trigger using trigger.old and trigger.new,
http://www.forcexplore.com/2014/03/compare-old-and-new-field-values-in.html
ketan mehtaketan mehta
Hi,
   Thanks for ur replies. As a resolution you are checking values manually but I don't want to do that. Is there any way I can compare the old object and new object without writing down the property comparision??