5 Tips Every Salesforce Developer Needs in 2021

Share this article...

As a Salesforce Developer, it is imperative to stay up to date with each new Salesforce release. Three times a year, Salesforce releases updates, features, and sometimes even a new language or framework. With each release, something that wasn’t previously possible becomes possible. For example, in the Spring ‘20 release WITH SECURITY_ENFORCED gave us a new era to check object and field level permission in SOQL.

In this post I will share 5 features every Developer needs in 2021.

“Validity”

1. Sharing rule needed for All Classes

As we know, for Visualforce page controllers and trigger helpers, we always use the “with sharing” keyword to enforce User access and permission. From Winter 2021, it will also be enforced for Aura and Lightning Web Component (LWC) based Apex classes.

Apex classes generally run in system mode. Consequently, the current user’s credentials aren’t used to execute Apex logic, and the user’s permissions and field-level security aren’t automatically applied. After this release we need to ensure the sharing permission for every Aura Enabled class so it will be consistent with Visualforce page controller access.

Check out the example below for AuraEnabled Class:

2. Use the Safe Navigation Operator

As Developers, we often worry about Null pointer exceptions, but as of Winter ‘21 this can now be resolved by Safe Navigation Operator (?).

Whereas before we were writing at least 2 or 3 lines of code to check null exceptions, now it is doable in a single line.

3. Use Salesforce Dynamic Forms before creating custom detail page UI

Salesforce Dynamic Forms is not just a feature for Admins! It can also help Salesforce Developers avoid redundant coding.

The premise of Dynamic Forms is to create user centric, intuitive page layouts that display the right information at the right time. Over time, the page layout, or “Details” section in Lightning pages, can become congested with fields. These fields may well be necessary but not all the time or to all users. The closest resolution we’ve had is to create multiple page layouts and different profiles, which is labour and config intensive.

With Dynamic Forms you’ll be able to:

  • Place fields anywhere on the layout without needing to add them to the traditional page layout (“Details” tab)
  • Use visibility rules to make fields and components appear and disappear based on criteria you choose
  • Do away with multiple page layouts
  • Improve page load times

You can either create brand new pages or migrate your existing Lightning Pages using the prompt shown below:

Once you’ve migrated or created a new Lightning record page, you will see the option to add a “Field Section” component which will then enable you to add fields directly to the Lightning record page.

4. Install Apex Recipe and LWC Recipe in your Developer Org to learn Best Practice

Apex Recipes is a library of concise, meaningful examples of code for common use cases following best practices”.

Source: Introducing Apex Recipes

Examples include how to write great triggers, how to make a callout and how to create Async class.

Similarly, LWC Recipes will provide code and examples for Lightning Web Components, such as how to learn to connect LWC with Apex, how to create a form, how to combine 2 components and so on.

Here is the list of all components and examples that LWC Recipe will provide for you:

5. Enforce Field-Level Security in Apex

Salesforce had System.AccessType class to check CRUD access in Apex and have recently added UPSERTABLE enum method in this class. Now, Salesforce has released the tripInaccessible method to enforce field and object level checks for both insert and update.

stripInaccessible can be used for the following:
To strip the fields that the current user can’t access from query and subquery results.
To remove inaccessible fields from sObjects before a DML operation to avoid exceptions.
To sanitize sObjects that have been deserialized from an untrusted source.

For example:

Source: Salesforce Developer guide

Summary

With every release Salesforce gives you new features and methods to explore. Developers must proactively keep up to date with all of these exciting changes to provide the best possible service to their customers, following best practices and utilising Salesforce features to get the greatest return on investment.

2 thoughts on “5 Tips Every Salesforce Developer Needs in 2021

Leave a Reply