You need to sign in to do that
Don't have an account?
System 181
Account deletion trigger
Hi All,
I am new to creating triggers and struggeling with this trigger, before deleting an account record to check TWO criterias,
if the field : acc.ninja_store_id is not blank - ( string )
if the a checkbox field : (deleted__c) is UNchecked -( boleean )
when I modify the trigger as below, it works only on the condition (deleted) but not on the string is blank
so, I want the rigger to prevent the deletion if one of the criterias is met!
here is the trigger:
I am new to creating triggers and struggeling with this trigger, before deleting an account record to check TWO criterias,
if the field : acc.ninja_store_id is not blank - ( string )
if the a checkbox field : (deleted__c) is UNchecked -( boleean )
when I modify the trigger as below, it works only on the condition (deleted) but not on the string is blank
so, I want the rigger to prevent the deletion if one of the criterias is met!
here is the trigger:
trigger test on account
(before delete){
for(Account acc: Trigger.old){
if(Acc.Account_Status__c!='Deleted' || Acc.Ninja_Store_Id__c != '' ){
acc.AddError('To be able to delete this account in SF, It has to be deleted first in Ninja');
}
}
}
Can you debug Ninja_Store_Id__c, what value you are getting in debug
Let me know then
Try Below Trigger Please Mark It As Best Answer If it Helps
Thank You!
Check below example that matches your requirement :-
https://developer.salesforce.com/forums/?id=906F0000000AW2HIAW
https://salesforce.stackexchange.com/questions/267416/trigger-for-preventing-account-deletion-with-related-opportunities
Please mark it as the Best Answer so that it can help others in the future.
Regards,
Priya Ranjan
Please follow the below code:-
trigger test on account(before delete){
if(trigger.isbefore && trigger.isDelete){
for(Account acc: Trigger.old){
if(Acc.deleted__c != true && Acc.Ninja_Store_Id__c != '' ){
acc.AddError('not able to delete');
}
}
}
}
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
So in my testing, if the account ninja status is blank it is still preventing me from deletion. Same as if the deleted check is false.