In my last question ( Implementing a Keyword Search ) , I described some of the complex queries I've been working on in a new app. In determining my approach, I'd like to consider the performance and speed of different queries, but I don't know how to profile the queries to understand how they're doing and what is causing bottlenecks or performance hits.

In SQL, I'd use EXPLAIN. What tools are available for SOQL, Salesforce, etc.?

1 Answer 1


You can gather some profiling information from your debug log. If you switch your log level to finest on Profiling, you can gain information such as this in the log which will at least give you execution time for each query:

07:06:23.980|CUMULATIVE_PROFILING|SOQL operations|
AnonymousBlock: line 8, column 1: [
    OpportunityId in :oppIds
    ]: executed 1 time in 972 ms
AnonymousBlock: line 1, column 1: [ select Id, c2g__Product__c, Opportunity__c from c2g__codaInvoiceLineItem__c where Opportunity__c != null and c2g__Invoice__r.c2g__InvoiceStatus__C = 'In Progress']: executed 1 time in 401 ms

07:06:23.980|CUMULATIVE_PROFILING|No profiling information for SOSL operations
07:06:23.980|CUMULATIVE_PROFILING|No profiling information for DML operations
07:06:23.980|CUMULATIVE_PROFILING|method invocations|
External entry point: public static void execute(): executed 1 time in 2128 ms
AnonymousBlock: line 3, column 1: global public system.Iterator iterator(): executed 7074 times in 37 ms
AnonymousBlock: line 5, column 1: global public Boolean add(Object): executed 7072 times in 16 ms
AnonymousBlock: line 2, column 1: global public SET<Id>(Integer): executed 1 time in 0 ms


You can do this under developer console by opening workspace manager and Change(ing) Log Levels.

  • This is great for profiling overall SOQL queries, but it sounds like there's no way (short of running different queries and checking results) of figuring out what factors contribute to the final speed, right?
    – Benj
    Dec 24, 2012 at 19:06
  • 1
    Worth noting is that the Developer Console has some nice GUI features for performance analysis as well, like Stack Tree->Performance Tree, or the Execution Overview with Limits, and Timeline where you can focus on Queries. The only thing that I had to do was cut down on some of the debugging, at one point it would only load Raw Logs. I've profiled some complex stuff and it was very helpful at pointing out / confirming the pain points. Nothing like Explain, though, as far as I know. It'd be interesting to experiment/study/benchmark common queries/join queries on/accross standard objects. Dec 26, 2012 at 22:22

You must log in to answer this question.

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