2

I've been trying to update a custom field metadata, specifically - update the valueSet.restricted to false to eliminate the restriction.
I already tried many different ways, adding or removing fields to the request body, the response error clearly says Only the Metadata and FullName fields may be specified on CustomFieldDefinition so I am only sending Metadata or these 2 together. I made sure FullName has the Object.field format, including the __c for custom field.
Whatever I do, I keep getting either this when sending the minimal request (object with only Metadata.restricted field, regardless of whether FullName is in the body or not):

  {
    "message": "Could not resolve standard field's name.",
    "errorCode": "FIELD_INTEGRITY_EXCEPTION",
    "fields": []
  }

I read somewhere I need to send the full Metadata object, which is quite large and then I got this error instead:

  {
    "message": "Cannot deserialize instance of complexvalue from VALUE_NULL value null or request may be missing a required field",
    "errorCode": "JSON_PARSER_ERROR"
  }

This is the HTTP request I'm sending (as well as without the FullName field):

curl https://xxx.salesforce.com/services/data/v62.0/tooling/sobjects/CustomField/00N3... -X PATCH -H 'Content-Type: application/json' -d '{"FullName": "Contact.Field1__c","Metadata":{"valueSet":{"restricted":false}}}'

I even tried this approach described here to use POST with a query parameter to indicate patch, but it still gives the same response.

Help? Anybody knows how to overcome this? I'm hoping this is possible with the Tooling API and I'm just missing something like required fields or something, but the null error throws me off whenever I'm trying to experiment with adding/removing fields to the valueSet object.

Thanks in advance.

1 Answer 1

2
{
    "message": "Could not resolve standard field's name.",
    "errorCode": "FIELD_INTEGRITY_EXCEPTION",
    "fields": []
  }

is an unfortunate red herring. It's a generic error message that comes up in many scenarios. Root cause: request payload does not meet the (undocumented) specification, the field name is not an issue.

Step 1: Create or choose an existing picklist field where values are restricted

Step 2: Retrieve the metadata definition of heretofore chosen field via Tooling API:

GET /services/data/<API version>/tooling/sobjects/CustomField/<field id>

Redacted response:

{
  "attributes" : {
    "type" : "CustomField",
    "url" : "/services/data/.../tooling/sobjects/CustomField/00N..."
  },
  "Id" : "00N...",
  "TableEnumOrId" : "01I...",
  "DeveloperName" : "...",
  [...],
  "Metadata" : {
    "businessOwnerGroup" : null,
    "businessOwnerUser" : null,
    "businessStatus" : null,
    "caseSensitive" : null,
    "complianceGroup" : null,
    "customDataType" : null,
    "defaultValue" : null,
    "deleteConstraint" : null,
    "deprecated" : null,
    "description" : null,
    "displayFormat" : null,
    "displayLocationInDecimal" : null,
    "encryptionScheme" : null,
    "escapeMarkup" : null,
    "externalDeveloperName" : null,
    "externalId" : false,
    "formula" : null,
    "formulaTreatBlanksAs" : null,
    "inlineHelpText" : null,
    "isAIPredictionField" : null,
    "isConvertLeadDisabled" : null,
    "isFilteringDisabled" : null,
    "isNameField" : null,
    "isSortingDisabled" : null,
    "label" : "Foo",
    "length" : null,
    "lookupFilter" : null,
    "maskChar" : null,
    "maskType" : null,
    "metadataRelationshipControllingField" : null,
    "mktDataLakeFieldAttributes" : null,
    "mktDataModelFieldAttributes" : null,
    "populateExistingRows" : null,
    "precision" : null,
    "readOnlyProxy" : null,
    "referenceTargetField" : null,
    "referenceTo" : null,
    "relationshipLabel" : null,
    "relationshipName" : null,
    "relationshipOrder" : null,
    "reparentableMasterDetail" : null,
    "required" : false,
    "restrictedAdminField" : null,
    "scale" : null,
    "securityClassification" : null,
    "startingNumber" : null,
    "stripMarkup" : null,
    "summarizedField" : null,
    "summaryFilterItems" : null,
    "summaryForeignKey" : null,
    "summaryOperation" : null,
    "trackFeedHistory" : null,
    "trackHistory" : false,
    "trackTrending" : false,
    "translateData" : null,
    "type" : "Picklist",
    "unique" : null,
    "urls" : null,
    "valueSet" : {
      "controllingField" : null,
      "restricted" : true,
      "valueSetDefinition" : {
        "sorted" : false,
        "value" : [ {
          "color" : null,
          "default" : false,
          "description" : null,
          "isActive" : null,
          "label" : "bar",
          "urls" : null,
          "valueName" : "bar"
        }, {
          "color" : null,
          "default" : false,
          "description" : null,
          "isActive" : null,
          "label" : "baz",
          "urls" : null,
          "valueName" : "baz"
        } ]
      },
      "valueSetName" : null,
      "valueSettings" : null
    },
    "visibleLines" : null,
    "writeRequiresMasterRead" : null
  },
  "FullName" : "SomeObject__c.SomeField__c"
}

Step 3: Build the request to modify the field definition.

We need the Metadata object and the FullName attribute. Do we need all of the Metadata object? No..but boiling it down to the minimum required parts is a tedious exercise. Thus, transformation of the payload is

  1. Grab the entire Metadata object as is
  2. Change the value of "restricted" from true to false
  3. Make "valueSettings" be an empty array. Pixie dust, undocumented.

Step 4: Issue the request

PATCH /services/data/<API version>/tooling/sobjects/CustomField/<field id>

{
  "Metadata" : {
    "businessOwnerGroup" : null,
    "businessOwnerUser" : null,
    "businessStatus" : null,
    "caseSensitive" : null,
    "complianceGroup" : null,
    "customDataType" : null,
    "defaultValue" : null,
    "deleteConstraint" : null,
    "deprecated" : null,
    "description" : null,
    "displayFormat" : null,
    "displayLocationInDecimal" : null,
    "encryptionScheme" : null,
    "escapeMarkup" : null,
    "externalDeveloperName" : null,
    "externalId" : false,
    "formula" : null,
    "formulaTreatBlanksAs" : null,
    "inlineHelpText" : null,
    "isAIPredictionField" : null,
    "isConvertLeadDisabled" : null,
    "isFilteringDisabled" : null,
    "isNameField" : null,
    "isSortingDisabled" : null,
    "label" : "Foo",
    "length" : null,
    "lookupFilter" : null,
    "maskChar" : null,
    "maskType" : null,
    "metadataRelationshipControllingField" : null,
    "mktDataLakeFieldAttributes" : null,
    "mktDataModelFieldAttributes" : null,
    "populateExistingRows" : null,
    "precision" : null,
    "readOnlyProxy" : null,
    "referenceTargetField" : null,
    "referenceTo" : null,
    "relationshipLabel" : null,
    "relationshipName" : null,
    "relationshipOrder" : null,
    "reparentableMasterDetail" : null,
    "required" : false,
    "restrictedAdminField" : null,
    "scale" : null,
    "securityClassification" : null,
    "startingNumber" : null,
    "stripMarkup" : null,
    "summarizedField" : null,
    "summaryFilterItems" : null,
    "summaryForeignKey" : null,
    "summaryOperation" : null,
    "trackFeedHistory" : null,
    "trackHistory" : false,
    "trackTrending" : false,
    "translateData" : null,
    "type" : "Picklist",
    "unique" : null,
    "urls" : null,
    "valueSet" : {
      "controllingField" : null,
      "restricted" : false,
      "valueSetDefinition" : {
        "sorted" : false,
        "value" : [ {
          "color" : null,
          "default" : false,
          "description" : null,
          "isActive" : null,
          "label" : "bar",
          "urls" : null,
          "valueName" : "bar"
        }, {
          "color" : null,
          "default" : false,
          "description" : null,
          "isActive" : null,
          "label" : "baz",
          "urls" : null,
          "valueName" : "baz"
        } ]
      },
      "valueSetName" : null,
      "valueSettings" : []
    },
    "visibleLines" : null,
    "writeRequiresMasterRead" : null
  },
  "FullName" : "SomeObject__c.SomeField__c"
}

If the request succeeds, the expected response status code is a 204.

Step 4: Repeat step 2 to verify the field definition no longer restricts values

4
  • Thank you! I kept playing back and forth with this undocumented API as you mentioned, and was able to boil down a similar resolution to what you outlined, with a minor update. At least from my experience, the metadata object needs to have all null values trimmed, otherwise they fail on invalid null values for complex objects or similar (I already forgot the exact error message). Plus, given they're null already - sending them again as null wouldn't change anything, so it's probably safe.
    – ZvikaT
    Commented Oct 7 at 16:50
  • 1
    I actually just re-read your message and realized I missed the pixie dust part, maybe that resolves the null issue as well. I'll try it, thanks! Regardless, simply trimming all null values recursively solves it as well (or so it seems)
    – ZvikaT
    Commented Oct 7 at 16:52
  • By the way, @identigral, is there an "easy tweak" to somehow do the same for global picklists ("Picklist fields that use a global picklist must be restricted") or overcoming picklist fields in managed objects (e.g. state=installed)?
    – ZvikaT
    Commented Oct 7 at 17:59
  • @ZvikaT Managed objects are not under your control. For non-managed, it would involve a technique similar to this Q&A - please post a new question if you can't get it to work.
    – identigral
    Commented Oct 7 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .