1

To assign correct FLS permissions in bulk for a given profile I need to know which fields are readonly and which fields support Field Level Security. I see that there is field IsFlsEnabled in FieldDefinition standard object, but it is not supported when I try to make SOQL.

Despite field IsFlsEnabled is present in documentation of FieldDefinition standard object, I received an error when I try to execute an SOQL in Apex code like

select Label, IsCalculated from FieldDefinition where IsFlsEnabled = True

No such column 'IsFlsEnabled' on entity 'FieldDefinition'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

How do I overcome this problem?

0

There is difference in fields available in Tooling API and SOQL, not every field from Tooling API is available for SOQL.

However, for Field Level Security it is easy to mitigate this problem by relying on two other fields which are available in SOQL like PublisherId and IsNillable.

Every field, which is not required and which is not system field, supports Field Level Security.

Also every field, which is not calculated, supports Edit permission.

So instead of querying for field IsFlsEnabled

select Label, IsCalculated from FieldDefinition where IsFlsEnabled = True

it is possible to query for PublisherId and IsNillable

select Label, IsCalculated from FieldDefinition where IsNillable = True AND PublisherId != 'System'

Also, if IsCalculated is true then field doesn't support Edit permission. If it is false then field supports Edit permission.

0

I am considering contact's email field before querying this field. I am checking isAccessible for the email field. Please see the below example.

if (Schema.sObjectType.Contact.fields.Email.isAccessible()) {
   Contact c = [SELECT Email FROM Contact WHERE Id= :Id];
}

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.