1

How can we upsert data to global picklist value by using apex?

I wanna catch record data from custom object by soql in apex, and upsert the data to global picklist value.

Thank you in advance.

1 Answer 1

2

You would want to use the GlobalValueSet metadata, and it is accessible via the Metadata API. To make updates to the metadata via apex, you can use the FinancialForce Metadata API Wrapper. Here is the repo.

Having said that, be careful in doing this. you could introduce some unintented regression and can create data quality issues.

3
  • 1
    not to mention that the running user needs customize application privileges and that might cause security issues
    – cropredy
    Jul 4, 2019 at 19:17
  • good point @cropredy... s'pose the OP wanted to circumvent that in real time trigger, what would they do? For nonreal-time, a scheduled batch job running as a sys admin ought to do the trick Jul 4, 2019 at 19:37
  • 1
    (1) use a platform event; runs as automated process user (might work, automated process user has some limitations); (2) do callout using named credentials where NC defines a user w/ customize app privileges
    – cropredy
    Jul 4, 2019 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.