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
PS81PS81 

Auto fill custom field based on picklist

Hi

I want to have a 2 custom field in Accounts called "Percentile" and "Probablility". The "percentile" is a picklist which has value like 10% - Deal upfront 20% - MoU etc and when ever a value is selected from "percentile" field I want to auto populate or auto fill the percentage value alone in the custom field "percentage". how to apprach this? pls advise.
Chris SweetChris Sweet
There are many ways to handle this from an elegant code-based approach to quick and dirty using workflow field updates or a formula.

For example, you could build a custom setting that maps Percentile values to Probabilities (e.g. "10% - Deal Upfront" --> 10%). When the Percentile changes, the trigger checks against that table to write the matching Probability to the Account. This method allows you to scale without any code updates by just adding/removing entries in the custom setting. This also allows you to use many different values that map to a single probability and wouldn't require any special formatting of the Percentile, so you could just say "Deal Upfront" maps to 10%, or "XYZ" maps to 20%, but also "ABC" maps to 20%.

A quick and dirty approach would be to just set up the Probability field as a formula. This would require that you set up the picklist values as you have lined out above. For example, the formula might look like this:
IF(LEFT(TEXT(Percentile__c),3)="100",1,VALUE(LEFT(TEXT(Percentile__c),2))/100)

The assumption here is that the formula's return type is set to Percent. This strips the number value from the first 2 characters of the picklist and divides by 100. I also added that if the first 3 characters are 100, it sets the value to 1.
PS81PS81
Thanks Chris. I did initially try with the formula but it seems to be a read-only which means when the account is saved the field i updated which is not the one I need. So I tried with workflow rules but it isnt working. Going by your thoughts I'm not clear on how to build the custom setting? can u throw some light on it please?
Chris SweetChris Sweet
That's correct, any formula field will be read-only. From your original post, it sounds like you need the Probability field to be solely based on the percentages displayed in the Percentile field. If that's the case, what is the need to be able to edit the Probability field? A workflow could do essentially the same thing using nearly the same logic, but you can keep the field editable.

A Custom Setting could be used here if you're going to go the trigger route. Your trigger should check to see if the value of the Percentile field has changed, and if so, it checks the new value against the custom setting mapping table and writes the resulting value into the account's Probability field.
PS81PS81
What is a "Custom Setting"? Where i can find and how could i configure it? please can you give some insight on it?
Chris SweetChris Sweet
You can learn about Custom Settings here: https://help.salesforce.com/apex/HTViewHelpDoc?id=cs_about.htm

They are essentially a dumbed-down type of Custom Object that typically holds static data that gets referenced in code, but can be updated by code as well. They can be incredibly useful, especially because accessing the table does not require a SOQL query.