2

Need to create or update the values of the global picklist using tooling API or Meta-data API.

0

You can retrieve, create, delete, and update the GlobalValueSet (Metadata) or the GlobalValueSet (Tooling) objects. You can do this both the REST and SOAP Metadata APIs, and the Tooling API.

  • 1
    Do you have some sample code ..? – user2815826 Oct 4 '17 at 6:14
  • @user2815826 I don't personally have any on hand, but the documentation for each API has sample code in it. What are you interested in? I could probably write up a short example in the morning. – sfdcfox Oct 4 '17 at 6:25
  • will get the picklist values from an API call at regular interval and needs to update if exists or else create a new global picklist with the values. – user2815826 Oct 4 '17 at 8:19
0

Working with Metadata API: Changing values of global picklists is available only starting from 37.0 API version. If your api version is 37.0, then you can use GlobalPicklist metadata

<GlobalPicklist xmlns="http://soap.sforce.com/2006/04/metadata">
    <description>Updated:This is a basic global picklist</description>
    <globalPicklistValues>
        <fullName>Northwest</fullName>
        <default>false</default>
    </globalPicklistValues>
    <globalPicklistValues>
        <fullName>Northeast</fullName>
        <default>false</default>
    </globalPicklistValues>
    <globalPicklistValues>
        <fullName>South</fullName>
        <default>true</default>
    </globalPicklistValues>
    <globalPicklistValues>
        <fullName>Southwest</fullName>
        <default>false</default>
        <isActive>false</isActive>
    </globalPicklistValues>
    <masterLabel>Territories</masterLabel>
    <sorted>true</sorted>
</GlobalPicklist>

content of package.xml

<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Territories</members>
        <name>GlobalPicklist</name>
    </types>
    <version>37.0</version>
</Package>

if your API version is 38.0 and later, GlobalValueSet is designed to work with global picklists

<GlobalValueSet xmlns="http://soap.sforce.com/2006/04/metadata">
   <description>Updated:This is a basic global value set.</description>
   <masterLabel>UpsellGlobal</masterLabel>
   <customValue>
      <fullName>Maybe</fullName>
      <default>false</default>
      <label>Maybe</label>
   </customValue>
   <customValue>
      <fullName>No</fullName>
      <default>false</default>
      <label>No</label>
   </customValue>
   <customValue>
      <fullName>Yes</fullName>
      <default>false</default>
      <label>Yes</label>
   </customValue>
   <sorted>false</sorted>
</GlobalValueSet>

and content of package.xml

<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>UpsellGlobal</members>
        <name>GlobalValueSet</name>
    </types>
    <version>40.0</version>
</Package>

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.