This article is prepared by our Salesforce Developer Aliaksandr Sheuka.
![](https://static.tildacdn.com/tild3132-6337-4863-b134-386162386533/Grey_line_1.png)
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 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.
![](https://static.tildacdn.com/tild6362-3964-4230-b864-633232656464/AS1-2.png)
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.
![](https://static.tildacdn.com/tild3263-6239-4966-b233-316438323036/AS3.png)
The result of the code is
![](https://static.tildacdn.com/tild3735-3934-4465-b635-393165303963/as4.png)
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
![](https://static.tildacdn.com/tild3231-3837-4034-a462-656532633365/as5.png)
- SOQL bind expressions do not support it
![](https://static.tildacdn.com/tild3865-6162-4036-b130-323561323335/as6.png)
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
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:
![](https://static.tildacdn.com/tild6433-6462-4630-b037-303230313531/as7.png)
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.
Roll back all uncommitted DML by using a savepoint.
![](https://static.tildacdn.com/tild3865-3662-4365-a563-316532616163/as8.png)
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.
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:
![](https://static.tildacdn.com/tild6461-3561-4362-b431-336665613732/as9.png)
- example 2:
![](https://static.tildacdn.com/tild3034-3263-4634-a164-303834643032/as10.png)
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:
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:
![](https://static.tildacdn.com/tild3163-3365-4730-b461-386537663736/as11.png)
There’s the result of compressing in an email.
![](https://static.tildacdn.com/tild6637-3438-4363-b730-643563636365/as12.png)
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.
![](https://static.tildacdn.com/tild3761-6133-4937-b031-323836363633/as13.png)
You can compare the header appearance with the new attribute applied and without it.
![](https://static.tildacdn.com/tild3539-3064-4233-b537-346633323733/as14.png)
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.
![](https://static.tildacdn.com/tild3830-3132-4530-a364-666330393630/as15.png)
Here’s what the example looks like in the UI:
![](https://static.tildacdn.com/tild6631-3064-4335-b264-363165396362/as16.png)
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.
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.
Summary
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.
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.
![](https://static.tildacdn.com/tild3066-3036-4634-a336-373432663531/Grey_line_1.png)