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

A milestone to celebrate: our 200th Salesforce certificate
November 19, 2020

A milestone to celebrate: our 200th Salesforce certificate

At Appsolutely we love learning, numbers and milestones (to name but a few). So when we see an oppor...

From a leap of faith to official FD Gazelle 2020
November 16, 2020

From a leap of faith to official FD Gazelle 2020

The word is out: Appsolutely has been awarded a FD Gazelle 2020! Het Financieele Dagblad (FD) awards ...

Meet Wenbo
November 1, 2020

Meet Wenbo

Nǐ hǎo and a warm welcome to Wenbo Liu, our new junior Salesforce developer from China! Since that’s ...