Salesforce Winter ’21 Release Highlights

In this post, We’re going to talk some cool features that were added as part of Winter ’21 release from Salesforce.

1. Apex Safe Navigation operator:

Use the safe navigation operator (?.) to replace explicit, sequential checks for null references. This new operator short-circuits expressions that attempt to operate on a null value and returns null instead of throwing a NullPointerException.

If the left-hand-side of the chain expression evaluates to null, the right-hand-side is not evaluated. Using the safe navigation operator(?.) in method, variable and property chaining. The part of the expression that is not evaluated can include variable references, method references or array expressions.

Ex :

This example first evaluates a, and returns null if a is null. Otherwise, the return value is a.b.

a?.b // Evaluates to: a == null? Null : a.b

This example returns null if a[x] evaluates to null. If a[x] does not evaluate to null and aMethod() returns null, then
this expression throws a null pointer exception.

a[x]?.aMethod().aField // Evaluates to null if a[x] == null

This example returns null if a[x].aMethod() evaluates to null

a[x].aMethod()?.aField

This example shows a single statement replacing a block of code that checks for nulls.

// Previous code checking for nulls
String profileUrl = null;
if (user.getProfileUrl() != null) {
profileUrl = user.getProfileUrl().toExternalForm();
}
// New code using the safe navigation operator
String profileUrl = user.getProfileUrl()?.toExternalForm();

 

2. Update Resources with the PATCH HTTP Method in Apex Callouts

Until the last Salesforce release, we do not have an option to PATCH request from Salesforce. To make partial or full updates to a resource in an HTTP web service, specify the PATCH method in the HttpRequest class. As compared to before where only the PUT method was supported for full updates.Find out more about this feature here.

3. Send Custom Notifications from Apex

Use the Messaging.CustomNotification class to create, configure and send custom notifications directly through Apex code such as a trigger.
Instead having API callouts from Apex, use CustomNotification to send notifications. It requires fewer lines of code and avoids API callout and authentication complexity. It’s also more efficient, which is especially helpful when you’re sending notifications from triggers or sending many notifications.
Using the Messaging.CustomNotification class to create and send custom notifications from Apex is easy. Create a new instance of CustomNotification, configure a few notification details, and call the send() method.

4. Detect Apex Runtime Context with RequestId and Quiddity

We can now detect Apex context at runtime and correlate multiple logs triggered by the request using Request ID and Quiddity values. Use the methods in the System.Request class to obtain the Request ID and Quiddity of the current Salesforce request.

First, use the Request.getCurrent() method to retrieve the Request object that contains the current Request ID and
Quiddity. To retrieve the Request ID from the Request object, use the Request.getRequestId() method. To retrieve Quiddity and its short-code, use the Request.getQuiddity() and System.getQuiddityShortCode() methods.
The Request ID and Quiddity values can be used to effectively correlate logs:
• The Request ID is universally unique and is captured in the debug logs triggered by the request.
• The Request ID and Quiddity values are the same as in the event log files of the Apex Execution event type used in Event Monitoring.

Example: This example shows how to retrieve and use Request ID and Quiddity.

//Get info about the current request
Request reqInfo = Request.getCurrent();
//Universally unique identifier for this request
//Same as requestId in splunk or REQUEST_ID in event monitoring
String currentRequestId = reqInfo.getRequestId();
//enum representing how Apex is running. e.g. BULK_API vs LIGHTNING
//Use this with a switch statement,
//instead of checking System.isFuture() || System.isQueueable() || ...
Quiddity currentType = reqInfo.getQuiddity();

5. Improve Apex Testing with New SObject Error Methods

Track errors with the new SObject.hasErrors() and SObject.getErrors() methods without performing a DML
operation to check the result for errors. Dynamically add errors to specific fields with new SObject.addError() overload methods.
Use the hasErrors() method to know if an SObject instance contains errors. Use the getErrors() method to retrieve the list of errors for a specific SObject instance.

This example code shows usage of the new SObject error methods.

//Baseline code sample for using addError, getErrors, together
Account a = new Account();
String msg = 'New error method in SObject';
//The new overload that accepts the field dynamically at runtime
a.addError('Name', msg);
List errors = a.getErrors();
System.assertEquals(1, errors.size());
Database.Error error = errors.get(0);
System.assertEquals(msg, error.getMessage());
System.assertEquals(StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION, error.getStatusCode());
String[] fields = error.getFields();
System.assertNotEquals(null, fields);
System.assertEquals(1, fields.size());

6. Customize Components with Lightning Design System Styling Hooks (Beta)

Lightning Design System Styling Hooks provides a set of CSS custom properties which can customize a component’s look and feel. In Winter ’21, a limited set of CSS custom properties is available for component-level customization.

Styling hooks make it easy to customize component styling and express your brand, especially when working with web components and shadow DOM. For a list of component blueprints that support styling hooks, see the Lightning Design System website. Click here for more info.

7. Write Lightning Scheduler Appointments Directly to External Calendars

Salesforce added a setting and developer resources to help you write Lightning Scheduler appointments directly to external calendars. When we enable the new Publish Appointments as Platform Events setting, Lightning Scheduler triggers platform events for new, modified or deleted appointments. We can capture and write those events to external calendars using APIs.

This method is an alternative to using calendar sync tools, which lets to synchronize your service resources, Salesforce calendars with external calendars. One of the benefits of using this method is that you can exercise greater control over the entire process.

We need to enable the Publish Appointments as Platform Events setting and subscribe to the new AppointmentSchedulingEvent platform event to receive event notifications when users create, modify, or delete appointments. Use an API to write the platform events directly to an external calendar. For example, use Microsoft Graph REST API to publish the events to Microsoft® Outlook®

8. Create Larger Emails with New Maximum Size of 35 MB

Salesforce increased the maximum size of outbound and inbound emails from 25 MB to 35 MB. The size of an email message includes the email headers, body, attachments and encoding. Email size can also vary depending on character set.

9. Secure Guest User Record Access Can’t Be Disabled

The Secure guest user record access setting was enabled in Summer ’20, but could still be disabled during that release. To safeguard your Salesforce org’s data, in Winter ’21, this setting is enabled in all Orgs with communities or sites and can’t be disabled. The Secure guest user record access setting enforces private org-wide defaults for guest users and requires that you use guest user sharing rules to open up record access. You also can’t add guest users to groups or queues or grant guest users record access through manual sharing or Apex managed sharing.

The timelines for the rollout and enforcement of this setting are published in Guest User Security Policies and Timelines.

10. Let Users Authenticate by SMS

You can now allow your external users to use SMS as a multi-factor authentication method. No need for downloading special apps. Verification can be as easy as getting a text message.

11. Trigger a Flow to Run Before a Record is Deleted

In Flow Builder, you can now configure a new record–triggered flow to run before a record is deleted. You no longer need to write Apex code to set this up. This autolaunched flow runs in the background and updates related records when a record is deleted.

12. Use AND, OR, and Custom Operators Across All Flow Builder Elements

Salesforce has taken the condition-defining options which we’re familiar with in the Decision and Pause elements and extended them consistently across Flow Builder. Specifying the condition logic to meet ANY conditions or to meet ALL conditions.

For example, specify contacts with the name Joe OR the city of San Francisco. Or you can provide your own custom logic. Salesforce has added these options to the Get Records, Update Records, and Delete Records elements, and to screen elements. You can also find the options in the Start element when configuring schedule- and record-triggered flows, and in record choice sets.

13. View Merge Field Labels in Flow Builder

Now get easy–to–read labels in the form of a pill for merge fields such as global constants and global variables. Salesforce is hiding the complexity of the merge field syntax but the syntax is still there if you need it. After you select a merge field and move to another field, the merge field’s label appears. The label doesn’t change the merge field value. With pills, you can click X to remove a merge field. The labels are available only in some areas such as logic elements, data elements, and screen component visibility.

14. Manage Deleted Fields in Lightning Experience

Salesforce added a feature to manage deleted fields in Lightning Experience. In previous releases, we could only manage a deleted field and its data by switching to Salesforce Classic.

15. Increased Timeout for Client-Side Caching

When a component is generated on the server from metadata, the page loads from a client-side cache of the indexed database. The client-side cache timeout has increased from 15 minutes to 8 hours, with a refresh interval of 15 minutes. This increased timeout can result in faster page loads for users who bootstrap the application frequently or click links from outside the application to open a new browser window or tab to Lightning Experience.

Also,  click here to get the release dates for Salesforce Winter ’21 release.