0

I have created a picklist called Period and it's API name is Period__c. Now, when a user clicks on that field then following values are shown , 1 week, 1 month, 6 month, 1 year.

Now, I have a requirement where if a user selects 1 week then internally the system should detect it as 7 days. If a user selects a year then if that field is used in some other part of the program then it should give 365 days.

So, I am trying to have a key-value pair. I looked at case object and i tried editing my field and kept the following formula but i am getting an error: Error: Field Period__c may not be used in this type of formula

The formula is: CASE(Period__c, "1 week", "7" "1 month", "30", "6 month", "180", "1 year", "365" "")

Any idea on this??

1
  • Why not just set the API values of the picklist choices to the number of days? Then you don't need a second field.
    – David Reed
    Commented Jan 31, 2018 at 12:16

2 Answers 2

1

Try to use below formula in the custom formula field that you have created. For Picklist field you need to use TEXT to compare

IF(TEXT(Period__c) = '1 week','7',
IF(TEXT(Period__c) = '1 month','30',
IF(TEXT(Period__c) = '6 month','180',
IF(TEXT(Period__c) = '1 year','365',''))))
0
trigger CaseeeeTrigger on Case (before insert,before Update) {
map<string,string> oppMap = new  map<string,string>();
 oppMap.put('1 week','7');
 oppMap.put('1 month','30');
 oppMap.put('6 month','180');
 oppMap.put('1 year.','360');

 for(Case cas : trigger.new ) {
    if(cas.Period__c != null) {
   cas.Period__c =  oppMap.get(cas.Period__c);
     }
  }
 }

Try something like this.Uncheck the checkbox Restrict picklist to the values defined in the value set

You must log in to answer this question.