I'm new to the world of Apex and have managed to cobble together this code that looks at a particular field and prevents deletion of that record if a particular field (in this case 'Data Source' isn't empty/null.
Although the code below works, it will prevent deletion if the field has any value in it and I need to customise it so that if a particular word is in that field, only then will it block deletion. But when I tried to specify this using code like "IBIS" (the name of an internal system I'm targetting), I got errors about incorrect data type.
Is what I'm trying to achieve possible?
My trigger code:
trigger IBISAccountDeleteTrigger on Account (before delete) {
for(Account acc : trigger.old){
if(acc.Data_Source__c != null)
acc.adderror('Sorry, we cannot delete this record as it came from IBIS.');
}
}
Data_Source__c is a Text field btw.
Thanks in advance :-)
if
statement that you tried to use when comparingData_Source__c
to'IBIS'
? You can edit your question to include that information.