User Story
As a system administrator, I want to create a trigger that fulfills the following conditions:
- When a new account is inserted, the Description field should automatically be set to "Contact created successfully".
- When an existing account is updated, the Description field should automatically be set to "Contact updated successfully".
Codes
trigger AccountBeforeInsertUpdate on Account (before insert, before update) {
for(Account ac: Trigger.new){
if(Trigger.isInsert)
{
ac.Description='Account created succesfully.';
}
else if (Trigger.isUpdate){
ac.Description='Account updated succesfully.';
}
}
}
trigger AccountBeforeInsertUpdate on Account (before insert, before update) {
for (Account ac : Trigger.new) {
switch on Trigger.operationType {
when BEFORE_INSERT {
ac.Description = 'Contact created successfully';
}
when BEFORE_UPDATE {
ac.Description = 'Contact updated successfully';
}
}
}
}
Video
Video does not exists.