Can't add item to custom Picklist in Salesforce with jsforce

377 Views Asked by At

I need to add an option to a custom Picklist in the Opportunity object whenever we release a new version of our software.

let metadta = [{
      "fullName": "Opportunity.Custom_Picklist__c",
      "label": "Custom Opportunity Picklist",
      "valueSet": {
            "restricted": "true",
            "valueSetDefinition": {
            "sorted": "false",
            "value": [
                        {
                              "fullName": "Option1",
                              "default": "false",
                              "Label": "Option 1"
                        },
                        {
                              "fullName": "Option2",
                              "default": "false",
                              "label": "Option 2"
                        }
                  ]
            }
      }
}];
conn.metadata.update('CustomField', metadata, function(err, results) {
      if(err) console.log(error);
      if(results) console.log(results);      
});

I have tried every variation that I can think of to update it and no matter what I do I get this error:

{
  "name": "soapenv:Client",
  "errorCode": "soapenv:Client"
}

I am using the documentation from https://jsforce.github.io/document/#metadata-api

1

There are 1 best solutions below

1
On BEST ANSWER

To add a field to your picklist, you need to create metadata. Specifically, the field you wish to add. Have a look at the CustomValue docs to see exactly the shape of the CustomValue. You can also update a field to be inactive using jsforce's update in a similar manner.

Here is a brief sample:

const metadata = [{
  fullName: "Opportunity.Custom_Picklist__c.SomeOption",
  default: "false",
  label: "Some New Option"
}];
conn.metadata.create('CustomValue', metadata, function(err, results) {
      if(err) console.log(err);
      if(results) console.log(results);      
});