Formula field bends itself beyond limits while keeping small footprint
5 minute read
Ever been struggling with formula fields using CASE() that suddenly is not able to compile because it contains too much data? Searching for solutions usually ends up in multiple formula fields and a workflow copying data to a new field and some new formula bringing that data in. In my case I needed to find a way of converting the Case language into a numerical value to be used in the calculation of Case score.
All numeric value/language pairs are stored in text fields (Language_Boost__c and Language_Boost_2__c) in the custom setting. The first field also contains the default value. After filling up the first text field in the custom setting record I just continued to put data in another text field and adjusted the formula (string concatenation) to bring in that data as well. So whenever you hit the field limit of 255 characters just add a new field. A numeric field was also added (Language_Boost_Digits__c) that contains the number of digits present in the text fields, in this case 3. If you need bigger numbers just set a bigger value in this field and change the number of digits for each value in the text fields.
The two custom setting fields look like this (I have removed data for readability). First value “000,” is default value, just as the last value in CASE(). Each value/language is made up of “nnn=xxxxx,” where nnn is the numeric value and xxxxx is the language. Default value and all languages must be appended with a “,” but you may use your own defined separator as well:
000,101=Brazilian Portuguese,102=Chinese (Hong Kong),105=English,
The formula looks like this:
For one of our customers I created a custom object to manage the language to score mapping. Then I wrote a trigger on that object that collects all records and creates the custom setting record field values automatically according to the format described above. That brings standard Salesforce GUI interface for managing the custom setting which is just great, and the customer knows for sure how to handle.
This example is just an eye opener for what formulas can deliver. By using concatenation of custom setting text fields the data limit used by formulas just increases a lot since data is not stored in the formula itself, only the reference. And there are many other use cases where you can store data in a smart and innovative format and create simple algorithms for using it.
Please let me know if you come up with something useful. Good luck!
Consultant, Architect and Developer
Fluido Favorites Summer '15
10 minute read