Tuesday, January 24, 2017

Picklists are more flexible now, in Salesforce

It was a difficult task for developers / admins to change a value in a Picklist in salesforce, as the values are directly stored in the records and if any formula fields are derived on picklist values, has to be changed. Similarly in the APEX / Visualforce code, if there is any logic based on picklist values, has to be changed.

Salesforce eased this burden in Spring 17 release.  Now on wards we have 2 values for a Picklist value, one is a label and other one is API name.
Basically the values stored in the back end in a record are API Names. When we try to get the value of a field, it fetches API value. From above picture, if we try to pull value for obj.Urgency__c, the result will be Urgent.

So, all our formulae fields' logic and also in the apex code, we can go with API names. And, we can change the label value at any point of time as per customer's need.

In order to display Picklist value in a visualforce page, make sure we go with OutputField only, to get picklist value label.  If we directly go by object field, it would display API name.

<apex:outputField value="{!obj.Urgency__c}"/>

 Few Points to consider for Picklist API Names:
  • For the first time when we create Picklist values, provided values will go into label and API Name
  • At any point, we are allowed to change API names too, by editing individual value.
  • We can also restrict API name updates through a setting. This blocks users from updating API names of all Picklist values in the Org.
  • To enable / disable above setting, go to Settings->Administer->Data Management->Picklist settings.
Reference, https://developer.salesforce.com/blogs/developer-relations/2017/01/keeping-picklist-integrations-safe-using-api-names.html

No comments:

Post a Comment