Skip to content

Instantly share code, notes, and snippets.

@sbob909
Created August 8, 2011 18:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sbob909/1132445 to your computer and use it in GitHub Desktop.
Save sbob909/1132445 to your computer and use it in GitHub Desktop.
Delete Restrict Trigger Example (Apex)
trigger DeleteRestrictAlbums on Album__c (before delete) {
// With each of the albums targeted by the trigger that have tracks,
// add an error to prevent them from being deleted.
for (Album__c targetAlbum : [SELECT Id
FROM Album__c
WHERE Id IN (SELECT Album__c FROM Track__c) AND
Id IN :Trigger.old]){
Trigger.oldMap.get(targetAlbum.id).addError(
'Cannot delete album with tracks');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment