Ever created a formula you were happy with, only to have it run up against the formula size limits? Did it have too many characters, or was its compile size too big?
If you need help streamlining your formulas, we’re pleased to announce our newest tip sheet for Summer ’13:
Inside, you’ll find tips and tricks for slimming down your formulas, both in number of characters and compile size, as well as example code, including:
- how to minimize the number of references to other formula fields
- how to minimize the number of times formula functions are called
- suggestions for rearranging your formula logic….and more!
We’ve got more formulas-related doc enhancements planned for the future, so stay tuned!
Here’s an excerpt from the tip sheet:
Suppose you have a Membership Start Date field, and you’re using that date to calculate a Membership End Date (in the interest of space, we’ll keep it short, but pretend it exceeds 3,900 characters):
IF( MONTH( Membership_Start_Date__c ) < 10, DATE( YEAR( Membership_Start_Date__c ), 12, 31), DATE( YEAR( Membership_Start_Date__c ) + 1, 12, 31) )
Because you repeatedly reference
YEAR(Membership_Start_Date__c), you can move that into a formula field called Start Year. You can also move
MONTH(Membership_Start_Date__c) into its own formula field.
Then the main formula becomes:
IF( Start_Month__c < 10, DATE( Start_Year__c, 12, 31), DATE( Start_Year__c + 1, 12, 31) )
You’re now down to 89 characters from 146. Since there are edition-based limits on how many fields you can create for an object, take them into account when figuring out how to break up a long formula. You might only want to create
Start_Year__c in the example above.
For more formula-related documentation, visit the Formulas page on DeveloperForce.