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
mwille64mwille64 

Is there a way to analyse the total number of SOQL calls made in a chain of flows and apex triggers executed through a single trigger event

Scenario from our custom Salesforce apps: 

A user creates a new Booking (custom object) via a dialog that allows the user to add a number of default Services (custom object), as well as to add one or more students (Contact object).

This in turn triggers a number of flows that create the sudent, link it via a generic junction object to the booking, this in turn triggers a flow that creates the services and assigns the student to the services. 

The Services are then calculated in terms of the sales and cost prices and when all is done the Booking is updated with the total value.

A few more things happen, which leads aside from all the optimisations I have implemented, to the famous SOQL 101 error when the number of default services exceeds about 6-8.

The problem is that each custom object has at least one flow attached that is triggered under certain rules. I find it absolutely impossible to trace exactly what is happening.

So the question is, is there a way in Salesforce or a 3rd party tool that can properly trace flow and trigger execution and comes up with an execution table and the number of SOQL calls made.

This would greatly help to see if there are any SOQL calls triggered that shouldn't be and ultimately allow to add further execution rules for unneccessary triggered flows and Apex triggers.
VinayVinay (Salesforce Developers) 
Hi Mwille,

Debug logs is only way to check and analyse SOQL calls made in apex, flow, trigger etc., Set debug level to finest and execute functional flow to check which operation is taken more time to execute and having multiple loops which might be hitting salesforce governor limits.

https://help.salesforce.com/s/articleView?id=000392579&type=1
https://help.salesforce.com/s/articleView?id=sf.code_debug_log_details.htm&type=5

There is no short way to debug immediately and find out reason for SOQL 10, you would need to review functional flow and review each component involved.

Please mark as Best Answer if above information was helpful.

Thanks,
mwille64mwille64
Thanks Vinay, your answer is appreciated.

I'm aware of the logs. But it is way too cumbersome to use the debug logs as a trace log for a particular event's 'trigger tree'. Debugging is limitted to the current flow opened for debugging. One can't debug what is triggered by the debugged flow. 

So either way, the provided functionality - as far as I understand it - is only useful up to a certain level of complexity. After that the current log and debugging implementation is useless (pardon for being frank here).

I stand corrected.
mwille64mwille64
...in addition: it is in matter opf fact quite easy to create a quasi 'endless loop' with flows triggering each other in a bounce until all sorts of org limits are hit. This is something that shouldn't be possible, or let me rephrase, could be avoided if proper trigger stack tracing had been implemented and flows had access to this information, such as:

was the current flow triggered by another flow?
if yes, which one?
what is the current bounce level?

The same applies to Apex triggers.
witherellson robbinwitherellson robbin
Analyzing the total number of SOQL (Salesforce Object Query Language) calls made in a chain of flows and Apex triggers executed through a single trigger event can be achieved by implementing custom logging mechanisms within your Salesforce code. You can create custom objects or use platform events to log each SOQL call and then aggregate the counts accordingly. For example, you might use a Log__c object to record each SOQL call, including the relevant trigger or flow, and then query this object to count the total calls. Keep in mind that this example link (https://thecuriositystation.com/home-security-companies-near-me-servleader/) doesn't pertain to the technical aspect of SOQL analysis but serves as an illustration of linking within a response.
mwille64mwille64
Thanks and yes, that would a possibility, but creating log__c entries or any other objects for that matter would - to my understanding - add to the number of SOQL calls and thereby distort the location where limit hits occur. It is also a bit messy with regards to the flows. So this is not relly the way to go about it. 

I solved my problem using the tedies dry work of charting step by step what the various flows and triggers are doing. This allowed me to I eliminate a few unneccessary double calculations/object updates and to optimise in terms of total number of calls. I'm for now back with in limits. 

Having said this, Salesforce should provide better tools for developers to analyse flow and trigger activities.