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
r nareshr naresh 

How to get old phone filed values after i update with new phone filed value using trigger

please give me example Thank u in advance
goabhigogoabhigo
For getting the old values in a trigger you can user Trigger.oldMap. Here is the detailed description about this - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm. Please go through "Context Variables Considerations" section too, to understand the whole funda better.

Eg code:
trigger YourTriggerName on ObjectName (before update) { 
      // Some code here
      String oldPhone;
      for (ObjectName var : Trigger.new) {
             // Access the "old" record by its ID
             oldPhone = Trigger.oldMap.get(opp.Id);
             // More code logic here
      }
}
Does this help? Do you need more information.

--
Abhi
Abhishek BansalAbhishek Bansal
You can use below syntaxt in your trigger :

OldPhoneValue = trigger.olMap.get(contact.id).Phone.

NOTE : trigger.oldMap is only available in update and delete triggers.

Thanks,
Abhishek
goabhigogoabhigo
My bad... Code should be: oldPhone = Trigger.oldMap.get(var.Id).APINameOfPhoneField; instead of oldPhone = Trigger.oldMap.get(opp.Id);.