0

My goal is to change field level permissions using REST API.

I'm trying to use API's in order to create a new field on Lead object and then write to it. That's the API call I used in order to create a new field:

token=get_token()

curl --silent -X POST \
-H "Authorization: Bearer ${token}" \
-H 'Content-Type: application/json' \
--data '{
  "FullName": "Lead.tamir_custom_field__c",
  "Metadata": {
    "label": "Tamir custom field",
    "description" : "test",
    "unique": "false",
    "type": "Text",
    "length": "20"
  }
}' \
"https://tamir--sandbox.my.salesforce.com/services/data/49.0/tooling/sobjects/CustomField"

That's working well. The field appears on Fields & Relationships menu on Lead settings, BUT I can't do nothing with it because it's missing the field-level permissions.

I'm trying to set those field-level permissions using this REST api:

curl -X POST \
-H "Authorization: Bearer ${token}" \
-H 'Content-Type: application/json' \
--data '{
  "fullName": "Standard User",
  "Metadata": {
    "fieldPermissions": [
      {
        "editable": "true",
        "readable": "true",
        "hidden": "false",
        "field": "Lead.tamir_custom_field__c"
      }
    ]
  }
}' \
https://tamir--sandbox.my.salesforce.com/services/data/${version}/tooling/sobjects/Profile

And getting this weird output!

[{"message":"Operation INSERT cannot be applied on EntityObject of type: Profile, id: 00e0D000000IHET through Tooling API: 00e0D000000IHET","errorCode":"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","fields":[]}]

So, how can I create field-level permissions for my new field using REST API? Is there another way to add permissions for my new custom field?

I will really appreciate some help here 🙏

2
  • I have answered to a similar Question here.
    – Saroj Bera
    Commented Apr 20, 2022 at 18:41
  • Thanks. Really helped! Commented Jun 25, 2022 at 7:14

0

You must log in to answer this question.