You need to sign in to do that
Don't have an account?
Nikhil Somvanshi
Error: There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Cannot Delete".
Hi People,
I am writing a simple code to refrain the user from deleting a record if it's active but getting the below error:
Error: There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Cannot Delete".
Here is my code:
trigger DontDeleteIfActive on Position__c (before delete) {
if(trigger.isdelete)
{
for (Position__c pos : trigger.old)
{
if(pos.Active__c != null || pos.Active__c == True)
pos.addError('Cannot Delete');
}
}
}
Put '&&' condition if(pos.Active__c != null && pos.Active__c == True)
Then it will only delete records that are not active else throws error