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
Lori_Lori_ 

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,
0))))))))))

 

Is there any way I can reduce the compile size?

 

Thanks!

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. 

 

CASE(Type__c,
"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,
0)

 

 

Lori_Lori_

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.

Lori_Lori_

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?

Lori_Lori_

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).