I am working on a class that dynamically created FieldPermissions
records for a permission set. This is working fine, except when it comes to standard compound address fields. When you attempt to create a FieldPermissions
record for Contact.MailingStreet
using the following code
PermissionSet perm = new PermissionSet(Name='Test_Perm_Set',Label='test Perm Set');
insert perm;
insert new FieldPermissions(SobjectType='Contact',PermissionsRead=true, Field='Contact.MailingStreet', ParentId=Perm.Id);
it errors out. Inexplicably, the error reads
FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Field Name: bad value for restricted picklist field: Contact.MailingCity: [Field]
Clearly not expected behavior, right there!
Even weirder, the FieldPermissions docs identify that a field will describe itself as not permissionable in it's describe result if you cannot create a FieldPermissions
for it. And yet...
System.debug(Contact.SObjectType.getDescribe().Fields.getMap().get('MailingStreet').getDescribe().isPermissionable());
Returns true.
Is this a platform bug that these fields are responding as permissionable? Is there some combination of describe flags that would let me know that they aren't permissionable?
EDIT: To answer a question from twitter, yes, there is no error when creating a permission for the Contact.MailingAddress
field. However, fieldsets contain the component fields instead of the compound field, so I'm looking for some logic other than hardcoded replaces to know to deal with the compound field (or at least not error on the components).