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

Product customizability and Overridable flows: Giving the controls to the customer
September 20, 2022

Product customizability and Overridable flows: Giving the controls to the customer

By: Hugo van Krimpen When developing Salesforce products for the AppExchange, we regularly face requ...

Hugo van Krimpen
By Hugo van Krimpen
Why you should stop just creating code!
August 10, 2022

Why you should stop just creating code!

By: Rodrigo Dantas Deep dive on Software Best Practices, and what we saw at TDX22 that backs up this ...

Rodrigo Dantas
By Rodrigo Dantas
How to connect and set up Salesforce Scheduler
May 17, 2022

How to connect and set up Salesforce Scheduler

By: Igmar Elizabeth Appointment scheduling in multiple languages What is Salesforce Scheduler and ho...

Igmar Elizabeth
By Igmar Elizabeth