I have a question regarding Salesforce FLS.

Is there any method available which dynamic check the object field-level security. Like I have Account object and Field name Phone and pass to any available method in Apex which returns true or false based on the profile permission


boolean method (objectname, fieldname){

return objectname.fieldname.isacceible();


Just FYI: I don't want to keep the field in the String Map like an example given in salesforce documentation: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_crud_fls.htm

  • What is your specific objection to using a Map? It's a pretty firm requirement if you want this code to work dynamically. – Adrian Larson Apr 30 at 18:10
  • I have more than 500 fields on the object and for every time a single field, I don't want to keep the map for all fields. – Faisal Apr 30 at 18:12
  • You don't need to construct it yourself...again, what is your specific objection? – Adrian Larson Apr 30 at 18:12

if what you want to do is to make sure that you don't send around fields that the user does not have access to, check out the Strip Inaccessible functionality

SObjectAccessDecision securityDecision = Security.stripInaccessible(sourceRecords);
Contact c = securityDecision.getRecords()[0];
System.debug(c.isSet('social_security_number__c')); // prints "false"
System.debug(JSON.serialize(c)); // will not display the social_security_number__c information
| improve this answer | |
  • This not work for me because my object and field both are dynamic, I already check this. like Security.SObjectAccessDecision securityDecision = Security.stripInaccessible( AccessType.READABLE, Sobject ); this give me error Method does not exist or incorrect signature: void stripInaccessible(System.AccessType, SObject) from the type System.Security – Faisal Apr 30 at 18:24
  • @Faisal, You need to pass a list of sObjects, even if the list only contains one record. For example Security.SObjectAccessDecision securityDecision = Security.stripInaccessible( AccessType.READABLE, new List<sObject>{Sobject} ); – Sergio Alcocer Apr 30 at 18:41
  • you are right but in my case, I have only one record and get the object instance dynamically sobject sObj = Schema.getGlobalDescribe().get(objName).newSObject(recordId); – Faisal Apr 30 at 19:09
  • It doesn't matter how you get the sObject, just pass it through. Maybe its clearer for you like this Security.SObjectAccessDecision securityDecision = Security.stripInaccessible( AccessType.READABLE, new List<sObject/*stays as sObject to indicate that is a generic one*/>{whateverYourSobjectVariableIs} ); The method accepts a List of any sObject, regardless if you know the type or not. Regardless if you query or instantiate it dynamically. – Sergio Alcocer Apr 30 at 22:42

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.