Skip to main content

Salesforce Spring 21 Release for Developers. Major changes

About Us
Published by jetbi
05 May 2021
28

The Spring ’21 release brought a lot of valuable features to Salesforce. New features provide great solutions in enhancing business productivity and development. We have prepared an overview of the most interesting updates for Developers.

  1. Create a Lightning Web Component Action (Pilot)

Create a Lightning Web Component (LWC) and use it as a quick action. Lightning Web Component actions work side by side on your pages together with Lightning component and Visualforce actions. LWC actions offer advantages such as the ability to easily customize headers and footers and to create actions that have no UI representation. Available to organizations that enable the pilot feature.

  1. Attach Actions to Asynchronous Apex Jobs Using Transaction Finalizers (Beta)

With Spring ’21, the Transaction Finalizers feature is in beta. A new limit establishes that a Queueable job that failed due to an unhandled exception may be re-enqueued five times by a Transaction Finalizer. This limit applies to a series of consecutive Queueable job failures. The counter is reset when the Queueable job completes without an unhandled exception. Finalizers can be implemented as an inner class. Also, you can implement both Queueable and Finalizer interfaces with the same class.

The System.FinalizerContext interface contains four methods:

  • getAsyncApexJobId method: Returns the ID of the Queueable job for which this finalizer is defined.
  • getRequestId method: Returns the request ID shared by both the Finalizer execution and the Queueable job to which the Finalizer is attached. This shared ID helps in filtering logs of a Queueable job and its attached Finalizer.
  • getResult method: Returns the System.ParentJobResult enum, which represents the result of the parent asynchronous Apex Queueable job to which the Finalizer is attached. Valid values for the enum are SUCCESS, and UNHANDLED_EXCEPTION.
  • getException method: Returns the exception with which the Queueable job failed when getResult is UNHANDLED_EXCEPTION, null otherwise.

To attach actions to your Queueable jobs, you must implement the FinalizerContext interface. Only one finalizer instance can be attached to any Queueable job. You can enqueue a single asynchronous Apex job (Queueable, future, or batch) in the finalizer’s implementation of the execute method. Callouts are allowed in finalizer implementations. For more information on implementing Transaction Finalizers, including examples, see Transaction Finalizers (Beta) in Apex Developer Guide.

  1. Obtain a map containing all custom metadata records or a single record sObject for a custom metadata type

Use the new Apex getAll(), getInstance(recordId), getInstance(qualifiedApiName), or getInstance(developerName) methods to retrieve custom metadata type records. So no more SOQL query to fetch custom metadata records.

Map<String, Custom_Metadata__mdt> allRecords= Custom_Metadata__mdt.getAll();

The sample below returns a single record sObject for the custom metadata type named Custom_Metadata_mdt with record ID specified as m00000000000001.

Custom_Metadata__mdt md = Custom_Metadata__mdt.getInstance('m00000000000001');

  1. Convert an 18-character Id value to a 15-character case-sensitive string

Use the to15() method in the System.Id class. This method uses the case-sensitivity checksum in the 18-character Id value to fix any mangled casing and returns a 15-character case-sensitive string.

Example:

String Id_15_char = '0D5B000001DVM9t';

String Id_18_char = '0D5B000001DVM9tkAh';

ID testId = Id_18_char;

System.assertEquals(testId.to15(),Id_15_char);

  1. SOQL, select all fields

Salesforce Object Query Language (SOQL) now makes it easy to include predefined groupings of fields within a query statement using the new FIELDS() function. Use FIELDS(ALL), FIELDS(STANDARD), or FIELDS(CUSTOM) in your SELECT statements.

In general new features improved the usability of the development. Now it is not necessary to create lightning components for using LWC in Quick Action. Also simplified custom metadata selection, which allows you to develop applications faster with custom metadata. New features speed up application development.


Sahib Gadzhiev
Software Engineer
Question to the expert