User Story
As a user, I want the Description field of a Contact record to be automatically updated with the message "This description has been updated before inserting" when a new Contact record is inserted, and with the message "This description has been updated before updating" when an existing Contact record is updated, so that I can easily identify which Contacts have had their description field updated and when. This should apply to any type of Contact insertion or update, such as via data import, API integration, or manual record creation and editing.
Code
trigger AccountTrigger on Account (before insert, before update, after insert, after update) {
if(Trigger.isInsert && Trigger.isBefore){
for(Account ac : Trigger.new){
ac.Description='This description has been updated before inserting.';
}
}
if(Trigger.isUpdate && Trigger.isBefore){
for(Account ac : Trigger.new){
ac.Description='This description has been updated before updating.';
}
}
}