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
Paweł WoźniakPaweł Woźniak 

Why CASESAFEID() is so expensive in formulas and how to workaround this?

Hi,
I have an junction object with three lookup fields to three budget types (other objects). They are filled in depended on selected record type.
As result of formula I want to have 18 character Id.
Formula:
CASE(RecordType.Name,
'Product Budget', EMS_Product_Budget_gne__r.Id,
'Region Budget', EMS_Region_Budget_gne__r.Id,
EMS_Territory_Budget_gne__r.Id)

Compiled size: 523 characters. Great but it returns 15char Id. Lets use CASESAFEID()
CASESAFEID( CASE(RecordType.Name,
'Product Budget Allocation', EMS_Product_Budget_gne__r.Id,
'Region Budget Allocation', EMS_Region_Budget_gne__r.Id,
EMS_Territory_Budget_gne__r.Id) )

Error: Compiled formula is too big to execute (9,780 characters). Maximum size is 5,000 characters.
CASE(RecordType.Name,
'Product Budget Allocation', CASESAFEID( EMS_Product_Budget_gne__r.Id),
'Region Budget Allocation', CASESAFEID( EMS_Region_Budget_gne__r.Id),
CASESAFEID( EMS_Territory_Budget_gne__r.Id) )

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

Why is it that expensive? Is there a way to wokaround this?



Ashish_SFDCAshish_SFDC
Hi , 


See the articles below, will help, 

http://www.crmverse.com/four-solutions-to-salesforce-com-too-big-to-execute-formula-error/

https://help.salesforce.com/HTViewSolution?id=000005456&language=en_US

https://help.salesforce.com/help/pdfs/en/salesforce_formula_size_tipsheet.pdf

Also see few similar threads, 

https://success.salesforce.com/answers?id=90630000000gsYIAAY

https://success.salesforce.com/answers?id=90630000000h3emAAA


Regards,
Ashish 
AgiAgi
Hi,

maybe you can put the 18 digit ids in text fields on each object and use these text fields in your formula.

1) create a new text field on each object  ex. 18digit id,
2) create a workflow rule
-evaluate the rule when a record is created, and every time it’s edited
-rule criteria: the above text field is blank  ex. Objectname: 18digit id equals null
3) add a field update action to update the text field
Specify New Field Value: CASESAFEID(Id)

you need to update the extisting records to fire the wf and then it can work
Daniel BallingerDaniel Ballinger
Each usage of the CaseSafeId() formula contributes 2073 characters towards the compiled formula limit of 5000 characters (as at v38.0). Any more than two uses of that formula will push you over the limit regardless of what the rest of the formula is doing.

It will likely be expensive as it is doing the complete suffix calculation each time. See What are Salesforce ID's composed of? (http://salesforce.stackexchange.com/a/1663/102)

Consider voting for the idea: Reduce the compiled formula character cost of CASESAFEID() (https://success.salesforce.com/ideaView?id=0873A000000cMmeQAE)
 
Hesham AhmedHesham Ahmed
I have an idea that I used before & succeded. I can use the "copy & paste" concept. This is done through the field update workflow. You can create a workflow that returns the values of the field that has the "CASESAFEID" formula in another text field. Then you can use this new text field in your formula. It won't conribute much characters then.