Find Object Permission and field level Security



Find Field Level Security and Accessibility:



APEX doesn’t enforce object level and field level permission by default. You can enforce this method by explicitly calling Schema.SObjectDescribeResult for object and Schema.DescribeFieldResult. In this way, you can verify if the current user has the necessary permissions, and only if he or she has sufficient permissions, you can then perform a specific DML operation or a query.


  •  Here two new fields named Relevant Experience and Total Experience has been created  
  • Relevant Experience - Field Level Security: Not Visible, Field Accessibility: Hidden
  • Total Experience - Field Level Security: Visible, Field Accessibility - Editable



Below code will explain it:

trigger EnforceSecurity on Contact (before insert, before update) {
        System.debug('Relevant Experience Updateable ' + Schema.sObjectType.Contact.fields.LightSample__Relevant_Experience__c.isUpdateable());
       
        System.debug('Total Experience Updateable ' + Schema.sObjectType.Contact.fields.LightSample__Total_Experience__c.isUpdateable());
       
        System.debug('Relevant Experience Creatable ' + Schema.sObjectType.Contact.fields.LightSample__Relevant_Experience__c.isCreateable());
       
        System.debug('Total Experience Creatable ' + Schema.sObjectType.Contact.fields.LightSample__Total_Experience__c.isCreateable());
       
        System.debug('Relevant Experience Accessible ' + Schema.sObjectType.Contact.fields.LightSample__Relevant_Experience__c.isAccessible());
       
        System.debug('Total Experience Accessible ' + Schema.sObjectType.Contact.fields.LightSample__Total_Experience__c.isAccessible());
       
        System.debug('Detail Permission on Contact ' + Schema.sObjectType.Contact.isDeletable());
} 














Below is the result from Debug Logs:




 

Comments

Popular Posts