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
GRStevenBrookesGRStevenBrookes 

Too many SOQL queries : 101

Hi All,

 

I know this is likely to be a two tier question, but looking first of all for some guidence on how i can find out what is causing the problem here.

 

Many thanks in advance:

 

Screenshot

GRStevenBrookesGRStevenBrookes

This is the trigger that is causing my problem - im trying to activate it and its throwing the errors above. but i NEED this trigger!!

 

trigger SARefreshSI on Service_Agreement__c (after update) {

  List<Service_Implementation__c> si = [select Id, Last_Refresh__c from Service_Implementation__c
   where Service_Agreements__c in: Trigger.new ];


for(Service_Implementation__c sic : si){
     sic.Last_Refresh__c = DateTime.now();
}
update si;

}

 

jungleeejungleee

Hi ,

 

Made few changes to your trigger.

 

trigger SARefreshSI on Service_Agreement__c (after update) {
	set<id> serAgrID = new set<id>();
	//Capturing the neccesary id.
	for(Service_Agreement__c sa: trigger.new){
		serAgrID.add(sa.id);
	}
	
	//using the ID to create a list to update.
	List<Service_Implementation__c> si = [select Id, Last_Refresh__c from Service_Implementation__c	where Service_Agreements__c in: serAgrID];
	list <Service_Implementation__c> siUpdateList = new list <Service_Implementation__c>();

	for(Service_Implementation__c sic : si){
		sic.Last_Refresh__c = DateTime.now();
		siUpdateList.add(sic);
	}
	update siUpdateList;
} 

 Hope this help!!

 

-Sam

 

GRStevenBrookesGRStevenBrookes

Hi,

 

Many thanks for your assistance, I am getting the following upon deploy:

 

 

GRStevenBrookesGRStevenBrookes

This is the other trigger referenced in that screenshot:

 

trigger updateCompletedWelcomeCallsSH on Service_Agreement__c (before update) {
  // Query for all SA records, plus any tasks they have marked
  // completed with the type of 'Sales Handover'
  for(Service_Agreement__c sa:[select id,(select id from tasks where type = 'Sales Handover' and status = 'Completed') from Service_Agreement__c where id in :Trigger.new]) {
    // Simply assign the list of the query to the correct field.
    Trigger.newMap.get(sa.id).COUNT_of_Completed_SalesHandover_Tasks__c=sa.tasks.size();
  }
}

 

Alex.AcostaAlex.Acosta

Any reason you're doing this on an after update trigger rather than before update trigger?

I'm supprised you're not hitting 'Maximum trigger depth exceeded' exception. Your trigger looks like it will be stuck in an infiniate loop.

GRStevenBrookesGRStevenBrookes
To be honest, I'm fairly new to triggers. Can you suggest anything? Sent from my iPhone
Alex.AcostaAlex.Acosta
trigger SARefreshSI on Service_Agreement__c (before update) {
     
     // loop through all records and update their last refresh value
     for(Service_Implementation__c sic :trigger.new){
          // add IF statement so you have conditions of when to update here, otherwise just use lastModifiedDate field
          sic.Last_Refresh__c = DateTime.now();
     }

}

 

jungleeejungleee

Hi Alex,

 

The SARefreshSI trigger is written on Service_Agreement__c object but the for loop is based on another object Service_implementation__c object, so you cannot have trigger.new in the for loop.

 

-Sam

GRStevenBrookesGRStevenBrookes

Effectivty, what I am trying to acheive here is when the Parent object is updated in anyway (Service_Agreement__c) that the Child record (Service_Implementation__c) which there will only ever be one of (enforced by validation) is updated in some way. 

Alex.AcostaAlex.Acosta

You are right, I was just crosseyed yesterday. Can't believe I made that mistake, but it happens =)

I'll poke at your other trigger later today if time allows.

GRStevenBrookesGRStevenBrookes
Many many thanks!!!
SFFSFF

It's probable, given that the error is happening during test class execution, that the sum of the queries in your test classes is greater than 100. If this is the case, are you using test.startTest() and test.stopTest() to limit the execution scope to an individual test method?

 

I mean, it is possible that there's something wrong with your code - but if there were, it would probably show up during regular testing in your org, right?

 

Hope this helps,

GRStevenBrookesGRStevenBrookes

Hi,

 

These are the tests referenced in the error:

 

MasterTestClass

@isTest
private class MasterTestClass {
static testMethod void MasterTestClass()
{
Account A = new Account ();
A.Name = 'Test Account';
insert A;
Contact C = new Contact ();
C.LastName = 'Tester';
C.AccountId = A.Id;
insert C;
Opportunity O = new Opportunity ();
O.AccountId = A.Id;
O.Primary_Opportunity_Contact__c = C.Id;
O.Name = 'Test Op';
O.CloseDate = system.today();
O.StageName = 'Opportunity Unquoted';
O.Service_Type2__c = 'GoMessage 24hr';
O.ReqGLD_Approved__c = TRUE;
O.RGL__c = system.today();
O.Background_to_Business__c = 'Test';
O.Why_is_customer_Outsourcing__c = 'Test';
O.Description = 'Test';
O.Average_Call_Duration__c = 1;
O.Average_Calls_Per_Month__c = 1;
O.Unsual_Requirements__c = 'Test';
O.Reporting_Requirements__c = 'Test';
O.Section_Complete__c = TRUE;
O.Frequency_Calls__c = 'Per Day';
o.CF_Record_Generated__c = TRUE;
o.Service_Length_Value__c = '4';
o.Projected_Service_Length__c = 'Months';
insert O;
Client_Financials__c CF = new Client_Financials__c ();
CF.Sage_Account__c = 'a1720000001oKb1';
CF.Opportunity__c = o.Id;
insert CF;
o.CF_Record_Generated__c = TRUE;
update CF;
echosign_dev1__SIGN_Agreement__c ES = new echosign_dev1__SIGN_Agreement__c ();
es.Name = 'Test Agreement';
es.echosign_dev1__Opportunity__c = O.Id;
es.echosign_dev1__Status__c = 'Signed';
insert ES;
O.echosign_AgreementsSIGNED__c = 1;
O.StageName = 'Closed Won';
update O;
Service_Agreement__c S = new Service_Agreement__c ();
S.Name = 'Test';
S.Related_Account__c = A.Id;
S.Related_Opportunity__c = S.Id;
S.Primary_Contact__c = C.Id;
insert S;
A.OwnerId = '00520000001Ry7W';
update A;
S.Survey_ncereq__c = TRUE;
update S;
Survey_Requests__c SR = new Survey_Requests__c ();
SR.Service_Agreement__c = S.Id;
SR.Scorecard__c = s.DEBUG_Scorecard_Lookup__c;
SR.Recipient__c = s.Primary_Contact__c;
insert SR;
s.Survey_nceissued__c = TRUE;
update S;
}
}

 

TestTopTrigger

 

@isTest
private class testopptrigger
{
private static testMethod void testopptriggerMethod(){
StaticClass.flag = false;
opportunity o = new opportunity();
o.StageName = 'Test Closed Won';
o.Name='Tester';
o.closedate=system.today();
o.secondary_lead_source__C='SB Database';
o.Projected_Account_Manager_ULOOKUP__c='005200000016quK';
O.CF_Record_Generated__c=TRUE;
insert o;
o.echosign_AgreementsSIGNED__c=1;
o.echosign_AgreementsOFS__c=1;
update o;
Service_Agreement__c service =new Service_Agreement__c();
service.name = o.Name + ' - ' + o.Service_Type2__c;
service.Related_Account__c = '0012000000ggi1T';
service.Related_Opportunity__c = o.id;
service.BD_Owner__c=o.OwnerId;
service.DEBUG_BDApprovalREQ__c=o.Sales_Script_Approval_Req__c;
service.Primary_Contact__c = o.Primary_Opportunity_Contact__c;
insert service;
Service_Agreement__C sa = new Service_Agreement__c();
sa.Related_Opportunity__c=o.Id;
SA.Related_Account__c = '0012000000ggi1T';
sa.COUNT_of_Script_Builds_In_Progress__c=1.0;
///Accs Approval Process Criteria - START///
sa.Name='test';
sa.CurrentlyInAccsApproval__c=FALSE;
sa.AccountsApproved__c=FALSE;
sa.Has_Account_Manager__c=TRUE;
SA.Skip_Process_Old_Account__c=FALSE;
///Accs Approval Process Criteria - END///
insert sa;
sa.COUNT_of_Completed_Script_Builds__c=1.2;
///Accs Approval Process Criteria - START///
sa.Name='test';
sa.CurrentlyInAccsApproval__c=FALSE;
sa.AccountsApproved__c=FALSE;
sa.Has_Account_Manager__c=TRUE;
SA.Skip_Process_Old_Account__c=FALSE;
sa.Sage_Account_Reference__c='AAA111';
///Accs Approval Process Criteria - END///
update sa;
case csa = new case ();
csa.Status = 'In Progress';
csa.Reason ='New Build';
insert csa;
Case cs = new case();
cs.Requested_By1__c=sa.Account_Manager__c;
cs.Service_Agreement__c=sa.Id;
insert cs;
Service_Implementation__c s = new Service_Implementation__c();
s.Name='Tester';
S.Service_Agreements__c=sa.Id;
s.COUNT_of_Signed_SIDs__c=1.0;
insert s;
o.StageName = 'Test Closed Won';
o.Name='Tester';
o.closedate=system.today();
o.secondary_lead_source__C='SB Database';
update o;
StaticClass.flag = false;
o.StageName = 'Test Closed Won';
o.Name='Tester';
o.closedate=system.today();
o.secondary_lead_source__C='SB Database';
update o;
SA.DEBUG_AccountManagerAllocated__c = TRUE;
SA.DEBUG_AccSUCCMCApproved__c =TRUE;
SA.DEBUG_AccSUCMCCreated__c = TRUE;
SA.DEBUG_ActiveITAInPlay__c = TRUE;
SA.DEBUG_BDApprovalCMCActive__c = TRUE;
SA.DEBUG_ActiveQATCMC_Rejection_InPlay__c=TRUE;
SA.DEBUG_ActiveSetLiveCMC__c=TRUE;
SA.DEBUG_FCACMCActionsCompleted__c=TRUE;
SA.DEBUG_ScriptBuildCMCCompleted__c=TRUE;
SA.DEBUG_ScriptBuildCMCCreated__c=TRUE;
update sa;

}
}

 

 

GRStevenBrookesGRStevenBrookes

Hi - does anyone have any ideas on this?