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
Rob CaseRob Case 

My compiled formula is too big to execute. Is there a way that it can be truncated?

I was trying to derive the state from area codes in leads and my compiled formula is too large.

I am trying to figure out a way to make it work.  Here is a sample of the formula...


and so on and so forth through all of the states with their respective area codes.  Seems simple enough, but needs to be simplified.

Any thoughts are much appreciated!
Gaurav NirwalGaurav Nirwal
1. Minimize the number of references to other fields
2. Minimize the number of times formula functions are called
3. Rethink your picklist
4. Think about the problem another way
5. If all else fails, use a workflow field update (or trigger)
Try using a CASE function instead of IF.
Shannon HaleShannon Hale
You can try something like this:
  LEFT( SUBSTITUTE( Phone, "(", "" ), 3 ),
  "205", "Alabama",
  "251", "Alabama",
  /* more area codes */
  "907", "Alaska",

One of the reasons you're hitting the limit is that you're using the LEFT() and SUBSTITUTE() formulas repeatedly. By using them once as the argument in the CASE() statement, you only add the compile size for that particular piece once. See the Tips for Reducing Formula Size ( tip sheet for more tips on reducing compile size.

But, even with the CASE() statement, I think you're going to run into problems. First, you're probably going to have too many characters for the 3900 character limit -- you can try to split it into multiple formula fields and then concatenate them together (e.g. Formula1__c & Formula2__c), but I suspect you'll still end up with a compile size issue.

If you can't reduce the compile size sufficiently, your best bet is probably a List custom setting and a trigger.