update availableOptions for multiselect Picklist through Apex trigger

1.2k views Asked by At

I have created a multiselect picklist which shows the list of users on a custom object. I want to update the available values on this picklist through trigger on User object whenever there is a new user created. I do not want to update the Chosen value. Also this is a field on a lightning page, not a vf or lwc or aura component. Is it a possible requirement? Please let me know if any further information required.

Field on Lightning page

enter image description here

1

There are 1 answers

0
David Reed On

Dynamically updating your org's schema based on data changes is both generally a bad idea and much more difficult than it sounds.

Your trigger would have to use Asynchronous Apex, such as a Queueable class, to call the Metadata API or Tooling API to update the picklist values. To do so, it must be authenticated as an administrator, so you'd also need to set up a Named Credential and authorize it as an administrator. And then you'd have to write the moderately complex code to actually create picklist entries based on Users, decide what to do when existing Users/picklist entries are deactivated, and so on.

It is generally a better pattern to implement a custom UI component (like a Lightning Web Component) where you need to present a dynamic picklist-style interface that's driven by data.