This trigger updates an Account’s Rating to “Hot” whenever its Industry field is set to “Media,” whether during creation or updates.
For additional examples, explore this YouTube playlist.
Solution:
trigger AccountTrigger on Account (before update) {
if(Trigger.isUpdate){ if(Trigger.isBefore){
AccountTriggerHandler.updateIndustryRating(Trigger.New, Trigger.oldMap);
}
}
}
public class AccountTriggerHandler {
public static void updateIndustryRating(List<Account>
accList,Map<Id,Account> oldMap){ for(Account
acc:accList){ if((oldMap==null &&acc.Industry==’Media’)
|| (acc.Industry==’Media’ && acc.Industry != oldMap.get(acc.Id).Industry)){
acc.Rating=’Hot’;
}
}
}
}