You need to sign in to do that
Don't have an account?
Richard Gilchrist
Bulkified trigger, still getting 'Too Many SOQL queries'
Hi,
I have a trigger written as:
I am receiving 'Too Many SOQL queries: 101' exceptions. I don't see how that's possible as this is bulkified and should only make one SOQL query per batch. Any ideas?
I have a trigger written as:
trigger UpdateLeadFunnelStage on CampaignMember (after insert) { Set<Id> LeadIds = new Set<ID>(); for(CampaignMember cm : Trigger.New) { LeadIds.add(cm.LeadId); } List<Lead> leads = [ SELECT Id, Lead_Funnel_Stage__c FROM Lead WHERE Id IN :LeadIds]; List<Lead> leadsToUpdate = new List<Lead>(); for(Lead l : leads) { if(l.Lead_Funnel_Stage__c == null || l.Lead_Funnel_Stage__c == '') { l.Lead_Funnel_Stage__c = 'Inquiry'; leadsToUpdate.add(l); } } Update leadsToUpdate; }
I am receiving 'Too Many SOQL queries: 101' exceptions. I don't see how that's possible as this is bulkified and should only make one SOQL query per batch. Any ideas?
Have a look here for more detail : https://help.salesforce.com/apex/HTViewSolution?urlname=System-LimitException-Too-many-SOQL-queries-101&language=en_US
Let me know if you need more help.
Please mark it as the solution if it answers your question so that others can also take benifit.
Thanks for the suggestion. I checked the Lead triggers and all of them are similarly bulkified, so they should only create one SOQL query per batch. There are some Lead triggers which are part of managed code, so I can't check those, but I'd hope they follow best practices.