Log Phone Updates in Description Field

This trigger logs changes to an Account’s Phone field in its Description. It displays the old and new phone numbers, maintaining an audit trail.

Explore more examples via this YouTube playlist.

Solution:

trigger AccountTrigger on Account (before update) {

              if(Trigger.isUpdate){ if(Trigger.isBefore){
                     AccountTriggerHandler.updateDescription(Trigger.New, Trigger.oldMap);
                }
        }
}
  public class AccountTriggerHandler {
        public static void updateDescription(List<Account> accList,Map<Id,Account> oldMap){
                  for(Account acc:accList){
                        if(acc.Phone!=oldMap.get(acc.Id).Phone){
                            acc.Description=’Phone is updated! Old Value :
                            ‘+oldMap.get(acc.Id).Phone+’ & New Value :
                            ‘+acc.Phone;
                    }
           }
      }
}

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)