+ Start a Discussion

Will changing nested IFs to CASE statement reduce the size?

I have a formula with a Compiled size of 4,215 characters.   The value of a picklist determines which formula is used.


This is a simplified version of the formula.


IF(ISPICKVAL(Type__c, "A"), formula1,
IF(ISPICKVAL(Type__c, "B"), formula2,
IF(OR( ISPICKVAL(Type__c, "C"), ISPICKVAL(Type__c, "D"), ISPICKVAL(Type__c, "E"), ISPICKVAL(Type__c, "F") ), formula3,
IF(OR( ISPICKVAL(Type__c, "G"), ISPICKVAL(Type__c, "H"), ISPICKVAL(Type__c, "I"), ISPICKVAL(Type__c, "J") ), formula4,
IF(OR( ISPICKVAL(Type__c, "K"), ISPICKVAL(Type__c, "L") ), formula5,
IF(ISPICKVAL(Type__c, "M"), formula6,
IF(ISPICKVAL(Type__c, "N"), formula7,
IF(ISPICKVAL(Type__c, "O"), formula8,
IF(ISPICKVAL(Type__c, "P"), formula9,
IF(ISPICKVAL(Type__c, "Q"), formula10,


Is there any way I can reduce the compile size?



Steve :-/Steve :-/

I've heard that CASE is more efficient that IF when it comes to Formula compile size.  I would think that this might help, since your "Master Formula" seems to be referencing just 1 Picklist Field, and then running a "Child Formula" based on the Picklist Value. 


"A", Formula1,
"B", Formula2,
"C", Formula3,
"D", Formula3,
"E", Formula3,
"F", Formula3,
"G", Formula4,
"H", Formula4,
"I", Formula4,
"J", Formula4,
"K", Formula5,
"L", Formula5,
"M", Formula6,
"N", Formula7,
"O", Formula8,
"P", Formula9,
"Q", Formula10,




Do I need to do anything w/ ISPICKVAL since it's from a picklist?

Steve :-/Steve :-/

No, you should be good-to-go, the big thing is gonna be if it gets you under the Compile Size Limit.


Well, this didn't quite work as planned.  Now, the compiled size is too big.


Error: Compiled formula is too big to execute (5,571 characters). Maximum size is 5,000 characters


Thanks for your help, Stevemo.

Steve :-/Steve :-/

Ouch!  I was afraid of that.  


What do your Formula_n Formulas look like?


There are 3 possibilities:

- its a field value (no calculation) 

- the calculation is embedded in this formula

- field refers to a calculation in another formula field


I tried substituting the actual calculations into this field, but it only dropped the size a little bit (<100).