+ Start a Discussion
daniel.knecht1.396874461719167E12daniel.knecht1.396874461719167E12 

Struggle with deployment: interfering class (Too many SOQL queries 101)

Hi all,

Developing a few triggers in our sandbox, I was about to get them deployed into our live org (100% coverage, all clean and good in test). However, in the live org, I always run into a conflict of "Too many SOQL queries 101". I have tried to bulkify my triggers (e.g. on queries in for loops etc) and eventually realized, it all comes down to a test class that someone else previously developed. In said test class, two methods cause the exceptions. My intention now is to 1) either clean up this test class OR 2) temporarily "deactivate" it to upload my triggers (not the preferred way).

To stick to no. 1, do you know what I need to consider in the below test class?

Many thanks in advance and best regards,
Daniel

@isTest
private class IntegrationQueueTrigger_TEST {

  static testUtils util = new testUtils();

  ////////////////////////////////////////////////////////////////////////////////////////////////////
  @isTest static void Insert_IPs() {  
    Test.startTest();
    List<Contact> ips = new List<Contact>();
    ips = util.createTestIpProjectStack(1, 'Test');

    List<Integration_Queue__c> items = new List<Integration_Queue__c>();
    Integration_Queue__c item = new Integration_Queue__c();

    item.Type__c   = sapIntegrationUtils.IP_INTEGRATION_NAME;
    item.Item_Id__c = ips[0].id;
    items.add(item);
   
    insert items;
    Test.stopTest();
  }
  
  ////////////////////////////////////////////////////////////////////////////////////////////////////
  @isTest static  void Insert_CAs() {
    Test.startTest(); 
    // Implement test code
    List<Contact> ips = new List<Contact>();
    ips = util.createTestIpProjectStack(1, 'Test');

    List<Integration_Queue__c> items = new List<Integration_Queue__c>();
    Integration_Queue__c item = new Integration_Queue__c();

    // get the account back (via placements) for this IP
    Account a = new Account();
    a.id = [Select id, ts2__Project__r.ts2__Client__c FROM ts2__Placement__c WHERE ts2__Employee__c =: ips[0].id].ts2__Project__r.ts2__Client__c;

    item.Type__c   = sapIntegrationUtils.CA_INTEGRATION_NAME;
    item.Item_Id__c = a.id;
    items.add(item);
          insert items;
    Test.stopTest();
  }
  
}

daniel.knecht1.396874461719167E12daniel.knecht1.396874461719167E12
Update: I have also adjusted the Test.startTest() and Test.stopTest() parameters to only cover the insert methods.

The trigger in question is the following:
trigger PotentialIPtoRole on ts2__Application__c (after insert, after update) { 
  List<ts2__Job__c> parentIPs = new List<ts2__Job__c>(); 
  public List<Id> listIds = new List<Id>();

  for (ts2__Application__c NewActive : Trigger.new) {
    listIds.add(NewActive.ts2__Job__c);
  }

  parentIPs = [SELECT id, Role_Status__c, IP_Name__c,(SELECT ID, Staffing_Status__c, ts2__Candidate_Contact__c FROM ts2__Applications__r) 
  FROM ts2__Job__c 
  WHERE ID IN :listIds];

  for (ts2__Job__c ActiveIP :parentIPs){

Boolean setToApproved = true;

For (ts2__Application__c rolIP: ActiveIP.ts2__Applications__r){
If (rolIP.Staffing_Status__c == 'IP on project') {

setToApproved = false;
break;
}
If (rolIP.Staffing_Status__c == 'IP finished project') {

setToApproved = false;
break;
}
If (rolIP.Staffing_Status__c == 'IP proposed') {

setToApproved = false;
break;
}
}
    
if (setToApproved){
     ActiveIP.Role_Status__c = '';
     ActiveIP.IP_Name__c = '';
  }
}
  update parentIPs;
}

The errors I get when validating the trigger in production are:

IntegrationQueueTrigger_TEST Insert_CAs System.LimitException: Too many SOQL queries: 101
Stack Trace: Class.testUtils.createTestApplications: line 212, column 1 Class.testUtils.createTestIpProjectStack: line 136, column 1 Class.IntegrationQueueTrigger_TEST.Insert_CAs: line 29, column 1

IntegrationQueueTrigger_TEST Insert_IPs System.LimitException: Too many SOQL queries: 101
Stack Trace: Class.testUtils.createTestApplications: line 212, column 1 Class.testUtils.createTestIpProjectStack: line 136, column 1 Class.IntegrationQueueTrigger_TEST.Insert_IPs: line 10, column 1