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.

 

 


Share this article:
twitter social iconfacebook social iconlinkedin social icon

divider graphic

Related

Secure third-party libraries in your managed package
May 26, 2021

Secure third-party libraries in your managed package

By: Hugo van Krimpen You are planning to release your very first application to the Salesforce AppEx...

Hugo van Krimpen
By Hugo van Krimpen
How to publish your SFDX plugin with these easy steps
April 6, 2021

How to publish your SFDX plugin with these easy steps

By: Guilherme Uhelski We all know that out-of-the-box commands that come with the Salesforce CLI onl...

Guilherme Uhelski
By Guilherme Uhelski
In the news: Capita's GrantIS live with the UK Department of International Trade
February 2, 2021

In the news: Capita's GrantIS live with the UK Department of International Trade

Appsolutely has the honour to work with Capita in the UK - a digital enabler of the grant management ...

Appsolutely
By Appsolutely