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
Pedro Garcia GPedro Garcia G 

add picklist value by apex

Hi...

I'm planning to deploy a managed package. I'm working in prove of concept (sandbox).

Once the app is installed, the user enters an API key to access to the third REST server. The REST server will provide the data to create Opportunity and the Opportunity.stage.
 
The Opportunity Stage is a picklist. How could I add a new stage value to the picklist?

The sf document says:
"Metadata access in Apex is available for Apex classes using API version 40.0 and later." at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_metadata.htm

but I didn't find how to do it?

Thanks,
Pedro

 
Pedro Garcia GPedro Garcia G
I don't understand what the documentation says

 
Global Picklists
Global picklists aren’t supported on custom metadata types. You can only use sObject picklists.
Picklists and Managed Packages
• You can add a custom metadata type that has a picklist field with inactive values to a managed package, but you can’t upload
the package. To upload the package, delete or reactivate the picklist values.
• Subscribers to a released managed package that contains a custom metadata type with a picklist field can’t add, delete, or
deactivate values from that picklist.
• Developers who release a managed packaged that contains a custom metadata type with a picklist field can add picklist values
but not delete or deactivate them.

so, Developers who release a managed packaged that contains a custom metadata type with a picklist field can add picklist values but not delete or deactivate them.

Does it mean that I can upload the picklist in the metadata and running the app I can add more picklist value? how?

Thanks