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
venkat gattamanenivenkat gattamaneni 

How to add field level security in apex while updating?

isUpdateable() - 

Returns true if the field can be edited by the current user, false
otherwise.

Is this a correct syntax ?

if(!CategoryMobileConfig__c.Active__c.getDescribe().isUpdateable()) // FLS 

{

update mobileAppConfig;

}

 

pujapuja

Hi,

The syntax is :

 

if (!Schema.sObjectType.CategoryMobileConfig__c.fields.Active__c.isUpdateable()){

//Do your work.

}

 

go to the  following url for reference :

http://wiki.developerforce.com/page/Testing_CRUD_and_FLS_Enforcement

asish1989asish1989

Hi

  Try this

        

       Schema.DescribeFieldResult f = CategoryMobileConfig__c.Active__c.getDescribe();

       

       Boolean notReadonly = f.isUpdateable()

       if( !notReadonly ){

update mobileAppConfig;

}

 You can refer this link .

http://boards.developerforce.com/t5/Apex-Code-Development/How-do-you-determine-field-level-security-field-visibility/td-p/175557

 

 

Did this solve your problem.. If so please mark it solved.. so that others get benifited.

 

Thanks

asish

            

Neha AggrawalNeha Aggrawal
Hi,

With the new feature released in Winter '19, now we can strip the fields which are not accessible by the user. More details are available on the below link: https://releasenotes.docs.salesforce.com/en-us/summer19/release-notes/rn_apex_Security_stripInaccessible.htm

I have also explored this feature in this post: https://initaura.com/field-level-security-in-apex/

Hope this helps.
Thanks and Regards, 
Neha Aggrawal
www.initaura.com - Everything Salesforce