My application constructs dynamic SOQL queries based on user interaction. The query can get quite large so I split the query into multiple queries based on the character count.

However, formula fields expand in length after you submit the query. Is there any way to programmatically determine the length of the expanded formula fields?

  • 2
    Can you contact SF support to opt-in the pilot program? Some clients got their SOQL length limit raised from 10 to 20K. Not really a solution but hell, if it helps you while you look for something better...
    – eyescream
    Commented Apr 18, 2013 at 21:55
  • This is for a managed package that gets installed in many orgs so this won't help me until the Summer release (when this feature becomes available to everyone).
    – cseaton
    Commented Apr 24, 2013 at 15:41

2 Answers 2


There is currently no way to get the length the formula field will be expanded to. Therefore you have to assume the worst-case for each formula field you want to query dynamically.

The current worst-case is 5k characters (details here). Since the current SOQL query limit is 10k* characters you can only include 1 formula field safely when you don't know the length ahead of time (e.g. dynamic SOQL).

*: The Salesforce Summer 13 release will increase the SOQL limit to 20k characters.


Out of the box, I don't believe there is. You can however click the "Check Syntax" button from the formula field edit page, which gives you the compile size. You could then use a custom setting or sObject to store a table of formula field api names and their associated compile size.

  • Is there any way to automate saving that information? I can see that stored data getting stale and obsolete quickly.
    – Mike Chale
    Commented Apr 18, 2013 at 19:04
  • 1
    Not that I know of. To mitigate that limitation you can enforce a lower query size limit threshold than salesforce (or oracle) is using. You can then perform multiple queries against this threshold and merge the results.
    – Phil Rymek
    Commented Apr 18, 2013 at 19:10

You must log in to answer this question.

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