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
HafaelDiasHafaelDias 

CRUD and FLS Enforcement

Hi there!

 

I'm enhancing the CRUD in my apex code and I would like to know if  I have to put that 'isUpdateble' or 'isCreateble' method field by field or if there's a way to get the whole object in just one method.

 

Because in my application there's a class that populate an object with many fields, so I would like to do it in a simple way.

 

 

You're wizard Harry!

 

Devendra@SFDCDevendra@SFDC

Hi,

 

You can check the field level security in apex as follows:

 

SObjectType sot = Schema.getGlobalDescribe().get(‘Account’); // Specify the Object API Name
List<Schema.SObjectField> lstFields = sot.getDescribe().fields.getMap().values();
for(Schema.Sobjectfield so : lstFields) {
    Schema.DescribeFieldResult dfr = so.getDescribe();
    if (dfr.isCreateable()) {
}

 

Similarly you can also check Object level permissions in Apex as follows:

 

Schema.DescribeSobjectResult  result = Schema.getGlobalDescribe().get('Account').getDescribe();
System.debug('1..#####'+result.IsAccessible());
System.debug('2..#####'+result.IsCreateable());

 Hope this helps :)

 

Thanks,

Devendra