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
Sukhpreet Lotey 6Sukhpreet Lotey 6 

Too many SOQL queries on tests

Hi all, 

Some tests are failing on my production org with error "Too many SOQL queries" but the tests passed on my sandbox which is a week behind from the prod site. So I started by looking at a particular test to find out where the problem lies by printing out the 'Queries Used' at different steps on the apex test code on both prod and sandbox. Interestingly I found out that an additional trigger was running on the production site which I am still trying to figure out why. The log has has something like:

11:10:37.169 (6359606075)|CODE_UNIT_FINISHED|Workflow:01IG0000002KhwC
11:10:37.169 (6361377923)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:ParentFieldUpdate
11:10:37.169 (6361471398)|CODE_UNIT_FINISHED|Workflow:ParentFieldUpdate

I am thinking maybe the problem might be here but cannot find a Workflow with 'ParentFieldUpdate'. Does anyone know what this could be?

Here are logs from both Prod and sandbox:

Production site:
11:10:07.496 (6909806810)|WF_FLOW_ACTION_BEGIN|09LG0000000PCDO
11:10:07.911 (6911029804)|FLOW_CREATE_INTERVIEW_BEGIN|00D170000000PkK|300G00000004rE5|301G0000000L7a7
11:10:07.911 (6911063628)|FLOW_CREATE_INTERVIEW_END|60139cd58510b6d5bf552215d318157529ae4ce-36f2|Dispatch Changing Original Date Rejected or Approved
11:10:07.912 (6912430672)|FLOW_START_INTERVIEWS_BEGIN|1
11:10:07.912 (6912482534)|FLOW_START_INTERVIEW_BEGIN|60139cd58510b6d5bf552215d318157529ae4ce-36f2|Dispatch Changing Original Date Rejected or Approved
11:10:07.912 (6918343468)|FLOW_START_INTERVIEW_END|60139cd58510b6d5bf552215d318157529ae4ce-36f2|Dispatch Changing Original Date Rejected or Approved
11:10:07.912 (6918354094)|FLOW_START_INTERVIEWS_END|1
11:10:07.496 (6919402559)|WF_FLOW_ACTION_END|09LG0000000PCDO
11:10:07.496 (6919433785)|WF_FLOW_ACTION_BEGIN|09LG0000000L0gi
11:10:07.921 (6921194785)|FLOW_CREATE_INTERVIEW_BEGIN|00D170000000PkK|300G00000004rGf|301G0000000PSvD
11:10:07.921 (6921236499)|FLOW_CREATE_INTERVIEW_END|60149cd58510b6d5bf552215d318157529ae4ce-36f1|Dispatch Currency Update
11:10:07.937 (6937772081)|FLOW_START_INTERVIEWS_BEGIN|1
11:10:07.937 (6937808252)|FLOW_START_INTERVIEW_BEGIN|60149cd58510b6d5bf552215d318157529ae4ce-36f1|Dispatch Currency Update
11:10:07.937 (6943548977)|FLOW_START_INTERVIEW_END|60149cd58510b6d5bf552215d318157529ae4ce-36f1|Dispatch Currency Update
11:10:07.937 (6943565494)|FLOW_START_INTERVIEWS_END|1
11:10:07.496 (6945020472)|WF_FLOW_ACTION_END|09LG0000000L0gi
11:10:07.496 (6945063573)|WF_TIME_TRIGGERS_BEGIN
11:10:07.496 (6958320240)|WF_ACTIONS_END| Field Update: 4; Flow Trigger: 11;
11:10:07.496 (6958337061)|CODE_UNIT_FINISHED|Workflow:01IG0000002KhwC
11:10:07.496 (6961000790)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:ParentFieldUpdate
11:10:07.496 (6961075944)|CODE_UNIT_FINISHED|Workflow:ParentFieldUpdate
11:10:07.496 (6964374035)|CODE_UNIT_STARTED|[EXTERNAL]|01qG0000000ipuf|AccountInformation on Charter trigger event BeforeUpdate for [a0r1700000Ax2xv]
11:10:07.496 (6978114250)|CODE_UNIT_FINISHED|AccountInformation on Charter trigger event BeforeUpdate for [a0r1700000Ax2xv]

Sandbox Log:
 
11:10:37.169 (6329081903)|WF_FLOW_ACTION_BEGIN|09LG0000000PCDO
11:10:37.330 (6330127573)|FLOW_CREATE_INTERVIEW_BEGIN|00D5B0000008dN8|300G00000004rE5|301G0000000L7a7
11:10:37.330 (6330173276)|FLOW_CREATE_INTERVIEW_END|6801c8b955c758d717542ec848f215752990e82-26e7|Dispatch Changing Original Date Rejected or Approved
11:10:37.331 (6331284858)|FLOW_START_INTERVIEWS_BEGIN|1
11:10:37.331 (6331309489)|FLOW_START_INTERVIEW_BEGIN|6801c8b955c758d717542ec848f215752990e82-26e7|Dispatch Changing Original Date Rejected or Approved
11:10:37.331 (6337066765)|FLOW_START_INTERVIEW_END|6801c8b955c758d717542ec848f215752990e82-26e7|Dispatch Changing Original Date Rejected or Approved
11:10:37.331 (6337076824)|FLOW_START_INTERVIEWS_END|1
11:10:37.169 (6337700220)|WF_FLOW_ACTION_END|09LG0000000PCDO
11:10:37.169 (6337729438)|WF_FLOW_ACTION_BEGIN|09LG0000000L0gi
11:10:37.338 (6338676531)|FLOW_CREATE_INTERVIEW_BEGIN|00D5B0000008dN8|300G00000004rGf|301G0000000PSvD
11:10:37.338 (6338722496)|FLOW_CREATE_INTERVIEW_END|6802c8b955c758d717542ec848f215752990e82-26e6|Dispatch Currency Update
11:10:37.339 (6339831759)|FLOW_START_INTERVIEWS_BEGIN|1
11:10:37.339 (6339856397)|FLOW_START_INTERVIEW_BEGIN|6802c8b955c758d717542ec848f215752990e82-26e6|Dispatch Currency Update
11:10:37.339 (6345584914)|FLOW_START_INTERVIEW_END|6802c8b955c758d717542ec848f215752990e82-26e6|Dispatch Currency Update
11:10:37.339 (6345594699)|FLOW_START_INTERVIEWS_END|1
11:10:37.169 (6346176796)|WF_FLOW_ACTION_END|09LG0000000L0gi
11:10:37.169 (6346220593)|WF_TIME_TRIGGERS_BEGIN
11:10:37.169 (6359597915)|WF_ACTIONS_END| Field Update: 4; Flow Trigger: 11;
11:10:37.169 (6359606075)|CODE_UNIT_FINISHED|Workflow:01IG0000002KhwC
11:10:37.169 (6361377923)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:ParentFieldUpdate
11:10:37.169 (6361471398)|CODE_UNIT_FINISHED|Workflow:ParentFieldUpdate
11:10:37.169 (6363663867)|USER_DEBUG|[57]|DEBUG|-UpdateRelatedDispatch Queries4: 50

Here you can notice on the list line that additional trigger spawns whereas on the sandbox it does not run.
 
Greg CooganGreg Coogan
Have you tried putting the Workflow Record ID in you URL? e.g. https://domain.my.salesforce.com/01IG0000002KhwC

This may lead you to which workflow is causing that operation to occur.
Harish RamachandruniHarish Ramachandruni
Hi,


one thing you have to check how many class you are moving is it diployed or not .

check which class is getting error .


See belo code .


It wont get any error belo 1oo Accounts avalable which org having  more 100 iit will get error .


checck which class getting error ,
list<Account>  Acclist = [select id,name from Account ];


for (Account Acc : Acclist)

{


Contact con = [select id,name from contact where Accountid = :Acc.id ];


}

Regards,
Harish.R
Priyanka S 27Priyanka S 27
Hi,

Looks like you have used the visua workflow. check the entire flow to determine what causes the record inser/update. If you find any DML operations occurs on the flow then check the trigger of the corresponding object. you will get to know the execution order.

Following are the two reasons that causes 'Too Many SOQL Error'
1) If the query is placed inside the for loop. It will hit the governor limits. 
2)  Recursive execution of particular method in trigger

Check the above and let me know if you could resolve it.

Thanks,
Priyanka s