SalesforceSummaries: a series delivering key insights from Salesforce YouTube videos, to save you time as you keep up to date with the latest technological changes within the Salesforce ecosystem.

Introduction:

In this presentation, a quick review of how the Salesforce security model will be presented. Then, an overview on how Apex code runs followed by best practices that you should adopt to ensure your Apex code is secure from a field level security perspective.

[email protected] — Contacts inherit the security settings from the account. And if you have contacts that aren’t related to an account, then that contact is private (only the owner has access to the account).

[email protected] — In summary, there are a number of different features that can be leveraged in Salesforce confirmatively to determine who can see and do what in the application. Crucially, all declarative configuration runs inside the user context. Meaning, that it runs within the bounds of all these settings and rules.

[email protected] — However, with regards to Apex code, this is slightly different. There are some special variations to point out when it comes to Salesforce security with Apex.

The most important distinction is that Apex runs in the system context and not the user context. Furthermore, in some situations, Apex lets you decide how to handle security.

[email protected] — Controllers are typically how you get access to data from Apex code. It is not best practice to use an indirect reference as this is a way in which data could be leaked.

[email protected] — An example of an indirect reference is line 11 in the code example below.

There is nothing in this code which ensures that people who should not have access to the value from the ‘Favorite_Color__c’ field do not see it.

[email protected] — The way to resolve this is, as per line 10, to add a single test. The isAccessible() method from the Schema sObject can be used to test whether a user has access to any object and/or field.

[email protected] — You should only write code for requirements that configurations cannot handle. Being able to leverage isAccessible() is helpful because you may want to write logic to say that ‘these sets of users can only access these sets of fields during business hours, and/or these sets of users can only access these sets of fields if these fields on the same record are of a certain value’.

SUBSCRIBE TO OUR MONTHLY NEWSLETTER

Connect with us

Address

Salesforce Ben
199 Bishopsgate
London
EC2N 4AG

Interested in guest posting?

Have something to share? Want to tell your story? We are always on the hunt for writers that interesting to say about the Salesforce platform and ecosystem. Join our group of 120+ trusted guest posters – Click here to start the conversation.