How many instances of "i" are there in:
Q: Too many SOQL - Need advice! So, I ran into a fun problem this morning. I have added a few new things to a trigger and am now getting the dreaded "Too many SOQL Queries" error. 
I inherited this code. It was originally created by an outside developer. 
I am looking for how to get around this error. Let me start out by saying the trigger is HUGE and it triggers another trigger. The second trigger is actually the one that is hitting the limit. 
So I tried to move some of the new code in the second trigger to a @Future class but that didn't help. Maybe I am misreading the notes on @Future but I thought it was supposed to reset the limits. 
I can't share any of my code as the triggers are HUGE and will be overly confusing for someone not working in our company as we mainly use custom objects. 
Can anyone tell me where I should look for ways to getting around the problem? I am aware of the trigger best practice guide and that queries shouldn't exist within loops. Unfortunately however there are some and it would take a long time for me to rewrite the triggers. 

A: Programming is easiest when you just focus on one problem at a time, the largest offender. Once it's fixed, move on to the next largest offender. Keep going until you're satisfied with the results. It doesn't matter if your triggers are thousands of lines each, you just need to narrow down your search to one small area.
To do this, open up the Developer Console, go to Debug > Change Log Levels, set everything to None, except for Profiling, which you change to FINEST. After that, simply cause the error to arise, then check the log file (in the Logs tab on the Developer Console).
Once you open the log, you'll see the queries used, the lines they occurred on, and how many occurrences of each there were. Choose the one with the highest count, fix it, then try again. Repeat the process until you're no longer failing, or you're satisfied with the results. Most of the time, fixing a SOQL governor limit problem is as simple as changing 3-5 lines of code.
The trick is to learn to read the logs efficiently. The governor limits rarely ever fault at the place that's causing the limit to be exceeded, so using Profiling is the key to finding where the performance bottlenecks are.

A: Chances are that your triggers on each object are firing in random order. The trigger you may think is causing the problem because that's where you saw the exception at, may not be the source. The too many SOQL is likely happening in one of the triggers before it. 
The @Future happens in a different execution context than your current trigger execution. Yes, it has higher limits, but those limits don't raise the limits of the current execution context, they just move them into the future into another execution context.

user
In that passage, there are one hundred and sixty-two occurrences of the letter "i."
assistant