Item:
Update Picklist Values on Package Upgrade
Share:
twitter social iconlinkedin social iconfacebook social icon
Image

Update Picklist Values on Package Upgrade

While upgrading the managed package we often forgot about the picklist field which has a limitation after winter 18 release. This can be quite tricky because we can add the values in picklist field and upgrade the package. The issue is realised when upgrading the package in subscriber Org when values are not upgraded. This is a generalised issue while upgrading any package containing picklist fields.

How to?

I faced this issue with one of the project involves update a manage package. While solving the issue I thought why not create a solution that is compatible with any package (managed or unmanaged) and can be independent.

I have used Metadata API services and created a solution to add new picklist values in custom Field. To make it independent I have used custom metadata to get the object field and new picklist values

Steps to follow to use the code 

 1. Add classes and custom metadata in your manage package.
 2. Add records (object name, field name, picklist value) in custom metadata.
 3. Run UpdateFieldValues.UpdateFieldValues();

Classes : MetadataService.cls, UpdateFieldValues.cls
Custom Metadata:  Picklist_Field_Definition__mdt
 

The code

Click here to view full code

Some examples

In the example below we have a custom field status__c on lead object.

Existing picklist values are 1, 2, closed. 

pastedGraphic.png

To add a new value in the picklist i.e ‘Open’ we need to add a record in custom metadata Picklist_Field_Definition__mdt check the screenshot below.

Custom Metadata

pastedGraphic_1.pngAfter adding the picklist in custom metadata we need to run method UpdateFieldValues.UpdateFieldValues() while upgrading.

After running the method the new value ‘Open’ will be added. 

Here is the final result:

pastedGraphic_2.png

If you have any questions please feel free to contact us.

 

 


Deel dit artikel:
twitter social iconfacebook social iconlinkedin social icon

divider graphic

Related news

Meet Naresh
September 21, 2020

Meet Naresh

Even though our new colleague Naresh Kumar is a senior salesforce developer, his eagerness to learn ...

Getting Listed on the AppExchange

Getting Listed on the AppExchange

Picture this: Your app development process reaches its end. The final tests were successful. Your pe...

Meet Sergio
August 21, 2020

Meet Sergio

In case you were wondering (and of course we all were ;-)): no, Sergio Mac Intosh is in no way relat...