function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
System 181System 181 

Lead deletion trigger

Hi all,
I am very new to creating triggers, I have the trigger below that I want to add the lead status to (id lead status is "in progree") do not allow users to delete, here is the trigger:
1
2
3
4
5
6
7
8
trigger deletion on lead
(before delete){
    for(lead lead: Trigger.old){
        if(lead.Ninja_Store_Id__c!=null){
            lead.AddError('You can’t delete this lead in SF, You can only abandon it');
        }
    }
}

Any help is so much appreciated
Thanks,
System 181System 181
Thanks a lot for the input. My initial question is about adding the ninja status criteria to my trigger. I want the trigger to check both if : ninja id field is not blank AND if lead status is in progress , does that make sense?
mukesh guptamukesh gupta
Hi ,

Please follow below code:-
 
trigger deletion on lead(before delete){
for(lead lead: Trigger.old){
if(lead.Status=='in progree' && lead.Ninja_Store_Id__c != '' ){
       lead.AddError('You can’t delete this lead');
   }
 }
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
CharuDuttCharuDutt
Hii System 181
Try Below trigger
trigger deletion on lead(before delete){ 
for(lead lead: Trigger.old){ 
if(lead.Status=='in progress' && lead.Ninja_Store_Id__c!=null){ 
lead.AddError('You can’t delete this lead'); 
  } 
 } 
}
Please Mark It As Best Answer If It Helps Thank You!
 
mukesh guptamukesh gupta
Hi,

I have already shared my code according your requirment in first look:-
 
trigger deletion on lead(before delete){
for(lead lead: Trigger.old){
if(lead.Status=='in progree' && lead.Ninja_Store_Id__c != '' ){
       lead.AddError('You can’t delete this lead');
   }
 }
}



if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh