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
Carly MandelCarly Mandel 

Too many soql queries - help bulkifying code

Hi Devs, 
I am an Admin that is very new to APEX. I have a a Lead Upsert action that is causing APEX Governing Limits error message of too many SOQL queries. We have a few different places where Leads are created, from Portals to Web-to-Leads, but I'm not 100% certain the source. Would anyone be so kind as to helping me source the cause , or provide any feedback for understanding which of my Lead Sources are causing the error? 

pconpcon
The most likely cause of this is using SOQL inside a loop, or calling a helper method that makes SOQL calls inside a loop.  I would first look in your code for any places that this occurs and then move the logic out.  I have written a blog post [1] that should help you get an idea of what bulk ready code should look like.  If you have any specific questions about how to make your code ready, please feel free to post it here and I will try to assist.  NOTE: Please use the "Add a code sample" button (icon <>) when adding your code to increase readability and make it easier to reference

[1] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/