Activity Forums Salesforce® Discussions How does Apex handle security and sharing?

  • Hariom Chaudhary

    Member
    August 14, 2019 at 7:41 am

    Hi Achint, I think

    Apex gives flexible user interface to add security level user permissions to share your code.To do this apex enforce sharing  rule as well as it also enforce object and field permissions

  • Deepak

    Member
    August 14, 2019 at 7:51 am

    Apex generally runs in system context; that is, the current user's permissions, field-level security, and sharing rules aren’t taken into account during code execution.​ The only exceptions to this rule are Apex code that is executed with the executeAnonymous call and Chatter in Apex. executeAnonymous always executes using the full permissions of the current user. For more information on executeAnonymous, see Anonymous Blocks.

    Although Apex doesn't enforce object-level and field-level permissions by default, you can enforce these permissions in your SOQL queries by using WITH SECURITY_ENFORCED. For more information, see Filter SOQL Queries Using WITH SECURITY_ENFORCED (Beta).

    You can also enforce object-level and field-level permissions in your code by explicitly calling the sObject describe result methods (of Schema.DescribeSObjectResult) and the field describe result methods (of Schema.DescribeFieldResult) that check the current user's access permission levels. 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.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos