1

We manage to create new fieldPermissions by calling updateMetadata() and passing to it a Profile object with the new fieldPermissions.

However, we haven't figured out a way to remove specific fieldPermissions nor a Profile object.

For example, if we want to change an object's custom field's permissions from standard to admin, we can only add the admin but can't remove the standard permissions. We've tried removing the Profile object but got an error from the metadata API: "cannot delete profile".

Example:

The current state of a field we wish to change: admin: { editable: true, readable: true },

The desired state: standard: { editable: true, readable: true },

What we end up with: admin: { editable: true, readable: true }, standard: { editable: true, readable: true },

(because we can add the standard fieldPermission to the field but can't remove the admin fieldPermission)

How do we achieve that?

  • Can you please edit your answer and provide more details around "if we want to change an object's custom field's permissions from standard to admin", can you give an example of a permission, and the desired end state? – CommonCoreTawan Jul 14 at 7:45
  • @CommonCoreTawan done. – ybro Jul 14 at 8:16
  • Object permissions aren't categorized as "standard" or "admin". Those are different Profiles, which are modified separately. How is your code selecting a Profile to modify? – David Reed Jul 14 at 14:28
  • Consider using Muted Permission Sets if / when they go GA – Brian Miller Jul 14 at 16:08
  • @DavidReed indeed the profile we modify is picked by the field level security. For example to add admin permissions to MyCustomObject type, the profile which we will add the field permission will be "Admin". The field permissions are named by the field's full name. For example: "{ field: MyCustomObject__c.Address__c", editable: permissions.editable, readable: permissions.readable, }". Adding such field permission to a Profile is easy, the unknown is how to remove one. – ybro Jul 14 at 16:41
0

Eventually the solution was to update the fieldPermissions to editable: false & readable: false on the relevant Profile object. That is the proper way to remove a field permission for a custom object through the Metadata API. The downside for it, is that the field permission will remain the the Profile object and will "garbage" the Profile.

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.