i have a tricky problem with an Apex Test Class for my Task Trigger.

enter image description here

While executing the related test class i get the "System.LimitException: Too many SOQL queries: 101" error in Trigger.Task: line 9, column 1?

Kind Regards danny

  • If you can post some code we can help you. Typically this happens due to SOQL queries in FOR loops. Can you check for this in your code? How many classes are you running test cases for?
    – Richard N
    Feb 4, 2015 at 20:12
  • @daniel-h - The code you posted is not the issue. Other code executing in the same transaction is causing the over utilization of the SOQL queries and your code posted above just happens to be the victim executing the 100th query
    – Eric
    Feb 5, 2015 at 22:53
  • I would look for recursize triggers as well - does Trigger Task do DML on some SObject and that object has its own Trigger, perhaps inserting Tasks?
    – cropredy
    Feb 6, 2015 at 1:30

2 Answers 2


This part of the trigger doesn't seem to have any queries in a for loop.

However, you can get the map directly from your query:

Map<Id,APQP_Phase__c> apqpPhases = new Map<Id,APQP_Phase__c>([SELECT Id,... FROM APQP_Phase__c]);
  • Yes, I think is also better to go with iiretepii solution: Map<Id, APQP_Phase__c> apqpPhase = new Map<Id, APQP_Phase__c> ([SELECT "your query"]); Should be more than sufficient. Feb 4, 2015 at 21:18
  • I didn't know that I could put code blocks in the answer textarea, so the page took away some of the syntax. Happy to help :) Feb 5, 2015 at 22:11

Maybe you should try to used a more "bulking" approach.
You can try something like this:

for(List<APQP__c> apqpList : [SELECT, "your query here"]){

  for(APQP__c theApqp : apqpList) {

   apqpPhase.put(apqp.id, apqp);

At least that will take up to 200 records per action and avoid the governor limits. Hope it helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .