function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ronmisronmis 

Update Dependent Picklist values through apex code

Hi guys,
          I have the following PickLists

Picklist_A
Values : 1, 2, 3, 4

Picklist_B
Values : L, M, N, O

Picklist_B is dependent on Picklist_A in this way
if 1 or 2 are selected from Picklist_A, Picklist_B will show L, M
if 3 or 4 are selected from Picklist_A, Picklist_B will show N, O

I'm trying to figure out how to write an apex method updatePickList() that will accept a string and add that to Picklist_B and make it dependent on Picklist_A 3,4

Thanks in advance

 
Satya Prakash ChoudharySatya Prakash Choudhary
Hi Ronmis,

If i understood correct, you want to add one new picklist value in in picklist field Picklist_B above and want to make them dependent on Picklist_A value.

This looks like the metadata configuration change. I think it's not possible to do it using APEX such type of changes.

You can try to explore the tooling api. That may help in this scenario.

Thanks.
Satya Prakash ChoudharySatya Prakash Choudhary
The other option you can use the metadata api as well. Can check below link for same:

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_updateMetadata.htm
 
ronmisronmis
Thanks Satya, I'll take a look. Basically an external team will like to add values to the the picklist via an api. so I can create a POST API for them, but I wasn't sure how to add values to the picklist via apex code.
Satya Prakash ChoudharySatya Prakash Choudhary
If this is just for supporting the external system creating the recored with a picklist value which is not available in available list of values, then just keeping picklist as "Un Ristricted" ( from Field setuup uncheck the restricted checkbox) would help. 

Only thing is this value which set by external system to picklist field, and not available in list of value, can not be used for other records when creating through user interface.

Please let me know if above help