Problem:
You need to create an apex trigger on the contact object which is fire whenever a new contact is created or updated and show the default description accordingly
Trigger code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger TgrContactBeforeInsertUpdate on Contact (before Insert, before Update) { | |
for( contact c : Trigger.new ) | |
{ | |
if(trigger.isInsert) | |
{ | |
c.description = 'contact created successfully by insert trigger '; | |
} | |
else if(trigger.isUpdate) | |
{ | |
c.description = 'contact update successfully by else update block'; | |
} | |
} | |
} |
Output :
Create a contact and check description is blank or not then hit save
When contact is inserted description will be
” contact created successfully by insert trigger”
And if we update the same trigger and hit save
After contact update description will be
” contact update successfully by also update block “
Try This Assignment :
You need to create an apex trigger on the contact object which modified user name when user updates contact.
Was this blog is useful?