Spring'24 changes in Salesforce for developers

This article is prepared by our Salesforce Developer Aliaksandr Sheuka.

Apex Enhancements

1) Null Coalescing Operator (??)

The ?? operator returns the left-hand argument if the left-hand argument isn’t null. Otherwise, it returns the right-hand argument. Similar to the safe navigation operator (?.), the null coalescing operator (??) replaces verbose and explicit checks for null references in code.

You will find the different options to check whether a value is not null on the image below. And as you can see, the new Null Coalescing Operator can really simplify your code, beautify it and make it more readable.
The operator can also be used to handle SOQL results which can return a single record or can return no records at all. For instance, you would love to find an account by a certain Id but a wrong Id has been passed. It leads to a QueryException. To avoid it, you can also use the new operator and handle this case.
The result of the code is
However, there are some restrictions on the Null Coalescing Operator:

  • it can not be used as the left side of an assignment operator in an assignment
  • SOQL bind expressions do not support it

2) Support of Randomly Generated UUID v4
Salesforce has introduced a very useful UUID class to generate a version 4 universally unique identifier (UUID). The UUID is generated using a cryptographically strong pseudo-random number generator and is represented as 32 hexadecimal values.

The class provides several methods which are listed below:

- randomUUID():

randomly generated a UUID that uniquely identifies an object

- equals(obj):

compares the UUIS instance with the specified object

- hashcode():

return the hashcode corresponding to the UUID instance

- fromString(string):

returns a UUID instance from a string representation of a UUID

- toString():

return the string representation of the UUID instance
Example of code:

3) You can now make callouts after rolling back your DML
Previously callouts after creating savepoints resulted in a CalloutException regardless of whether there was uncommitted DML or the changes were rolled back to a savepoint. Now you can use the new Database.releaseSavepoint() method to explicitly release savepoints before making a callout and roll back all uncommitted DML to a specific savepoint.

Roll back all uncommitted DML by using a savepoint.

4) Evaluate Formula at Apex runtime
This feature is currently available for developer preview only. However, I found it very useful as it allows us to evaluate user-defined dynamic formulas for Apex objects and Sobjects without using database CPU.

For now, this feature is available in scratch orgs only where the FormulaEvalInApex feature is enabled. If it isn’t enabled, Apex code can be compiled but not executed.

To create an instance of the formula, call the static method builder() in the FormulaBuilder class by specifying the formula text and context object. To validate the formula instance, call the build() method. The FormulaValidationException exception is thrown if validation fails.

To calculate the formula expression and return the result, use the evaluate() method in the FormulaInstance class. The FormulaEvaluationException exception is thrown if validation fails.
Here’s an example that uses the mentioned methods:

  • example 1:
  • example 2:
In my opinion, this is a very useful and convenient feature and hopefully, it’ll become available in all orgs in a while.

5) Compress and Extract Zip files in Apex
This is another useful feature which is currently available for developer preview only. The methods from the new Compression namespace can help you compress and extract files and allow zipping files in Apex code without external dependencies.

This feature is available in scratch orgs where the ApexZipSupport feature is enabled.

You can use the methods in the new Compression namespace to easily generate and extract compressed zip files. You can specify the compression method and level. You can compress multiple attachments or documents. You can also specify the data to extract from the zip archive without uncompressing the entire zip archive.

Here’s an example that uses this feature to compress a file and then send it:
There’s the result of compressing in an email.

Lightning Web Components Enhancements

1) Wrap Table Header in lightning-datatable component
The lightning-datatable component now includes a new attribute called wrap-table-header, allowing the header text to wrap within column widths.
You can compare the header appearance with the new attribute applied and without it.

2) Lightning-record-picker help text and availability
Two new attributes are added:

  • field-level-help – help text that details the purpose of the record picker component. The text displays on hover for desktop and on click for mobile experiences.
  • disabled – when this attribute is present, the component is disabled and a user cannot interact with it.
Here’s what the example looks like in the UI:

3) New generally available components and features
Some component features which was in beta earlier are generally available now. Some of them are listed below:

1) Control Workspace Tabs and Subtabs

The LWC Workspace API provides methods to manage your workspace tabs and subtabs in a Lightning console app. This feature, which is now generally available, includes minor bug fixes and improvements since the beta release. The change applies to Lightning console apps in Enterprise, Performance, Unlimited, and Developer editions.

2) Search for Records with the Lightning Record Picker Component

Use the lightning-record-picker component in a Salesforce application so that desktop and mobile users can quickly find and select Salesforce records. Configure the component’s behavior and presentation, and enable filtering so that users can retrieve and display precisely the records that they want. This feature, now generally available, includes some changes since the last release. You can now retrieve up to 100 records. Previously, it was 50 records. The component also displays clear error messages when you configure invalid specifications and supports new attributes. This component uses the GraphQL wire adapter, which enables offline use.


This is a short overview of the most interesting, useful and vibrant Salesforce Spring ’24 release features, tailored especially for developers who deal with Apex and LWC.