You need to sign in to do that
Don't have an account?

Bulkify Lead after insert to delete record
Hello
I am wanting to delete the lead record which triggers the after insert oif the field TriggerDelete__c=true
I get an soql 101 error due to it not being batchified from my test class inserting 200 records.
Can anyone give me a pointer on how I would do this?
trigger Lead_HDL_AI on Lead (after insert) { //list<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; for(Lead record: Trigger.new) { //Query Lead List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; //Delete Lead if(record.TriggerDelete__c==true){try{DELETE LeadList;}catch(Exception e){} } } }
I have fixed your code. Now below code is working fine. Please try below code:- Please let us know if this will help you
Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com
All Answers
Remove soql from for loop, if im not wrong you can use the below query as such:
List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id in : trigger.new and TriggerDelete__c==true];
delete leadlist;
Thanks.
Please try below code
Please let us know if this will help you
@Amit Chaudhary 8
Thanks for your reply. Unfortuantly your solution did not work. The lead record still saves and leaves the TriggerDelete__c==true, where it should produce the "record has been deleted" page.
@SF DEV
Thanks for your reply. Do you have a sample of what the full code would be? I dont believe your solution would be batchified for mass batch record inserts?
I have fixed your code. Now below code is working fine. Please try below code:- Please let us know if this will help you
Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com