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?