Skip to content

Instantly share code, notes, and snippets.

@lfreeland
Last active February 22, 2019 17:21
Show Gist options
  • Save lfreeland/ce1b1a00dc78e5e61516323c0096d490 to your computer and use it in GitHub Desktop.
Save lfreeland/ce1b1a00dc78e5e61516323c0096d490 to your computer and use it in GitHub Desktop.
Update Trigger Validation Example
trigger myAccountTrigger on Account (before delete, before update) {
if (Trigger.isBefore) {
if (Trigger.isUpdate) {
for (Account newAcct : Trigger.new) {
Account oldAcct = Trigger.oldMap.get(newAcct.Id);
if (oldAcct.Name != newAcct.Name &&
newAcct.Name.containsIgnoreCase(‘Luke’)
newAcct.addError(‘Choose a better name’);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment