Workaround for 5000 characters limit on Formula Field in Salesforce

If you are working with formula fields in salesforce then you might have seen this message : 

“Compiled formula is too big to execute. Maximum size is 5,000 characters.” 


This means that the query generated by your formula syntax is too big for the database to handle all at once. Formula size problems come in two flavors: the formula is too long, or its compiled size is too big. 


If you are thinking to reduce the number of characters in your formula, it's not going to work. Comments, white space and field name length make no difference on the compile size.


If you are planning to break the formula into multiple formulas fields, that doesn't going to work either as the compile size of each field is included in the main formula’s compile size.


There could be multiple ways to get rid of this issue but the best one is to use a Workflow field update : 


  1. Create a custom field of the type your field update formula will return, such as Date or Number. Don’t add it to any page layouts.
  2. Create a workflow rule on the object. Set it to execute whenever a record is created or updated.
  3. Create a Field Update workflow action. Choose the custom field you created in Step 1 as the target, and copy part of your large formula into the formula that sets the value in that field.
  4. In your formula field, replace the part of the formula you copied to the field update action with a reference to your custom field.
After updating the reference to your custom fields formula's compiled size will be reduced as we are not using any direct functions for value references in it, instead of that we are using a custom field value generated using workflow.

 If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 


Post a Comment

1 Comments

  1. I recently published an app named Unleash Your Formula. https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3u00000MS8T1EAL

    The app does something simple, it copies and syncs formula fields to the specified non-formula field (of the same type). This is an effective way to handle character limits.

    Most character limit issues arise because the formula is referencing another formula, often multiple times, and each additional reference increases the formula character size by the size of referenced formula field.

    With this app, you can reference instead the mapped non formula field, which will quickly reduces the character limit.

    Even if you indeed have 5000 characters in a single formula, you can split it up into multiple formulas and use the same trick.

    ReplyDelete