function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dotnetericdotneteric 

How do you determine field-level security / field visibility?

Is there a way to determine field-level security (aka field visibility) for a profile or for the logged in user's profile through Apex?
Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

From the doc:

 

 

Schema.DescribeFieldResult f = Account.AccountNumber.getDescribe(); Boolean notHidden = f.isAccessible(); Boolean notReadonly = f.isUpdateable();

 

This returns the values for the running user. You can't check for other profiles at runtime but you can in test context using System.runAs(). See the Apex Developer Guide for more information.

 

All Answers

mtbclimbermtbclimber

From the doc:

 

 

Schema.DescribeFieldResult f = Account.AccountNumber.getDescribe(); Boolean notHidden = f.isAccessible(); Boolean notReadonly = f.isUpdateable();

 

This returns the values for the running user. You can't check for other profiles at runtime but you can in test context using System.runAs(). See the Apex Developer Guide for more information.

 

This was selected as the best answer
APEX Dev.ax783APEX Dev.ax783

Would this code work at the object level also?

mtbclimbermtbclimber

Yes the same methods are available on the SObject describe result. See the apex dev guide referenced above for the syntax.