Salesforce Spring’24 Features: Key Updates for Developers


Explore tailored picks for developers in Salesforce Spring ’24! Discover key features designed to enhance and streamline development processes.

Lightning Web Components Enhancements : Salesforce has made several changes to existing lightning web components and introduce new components as well.

  • lightning-datatable :
    • wrap-table-header new attribute is added. It allows the header text to wrap within column width.
    • Supports custom data source component for dynamic determination at run time based on context.
  • lightning-input :
    • role new attribute is added. It creates an accessible combo box using lightning-input instead of the lightning-combobox component or a custom component. Set role="combobox" and type="text" to create a combo box. The only valid value for role is combobox.
  • lightning-pill-container :
    • href new attribute is added. It adds a link to a pill in the container.
  • Control Workspace Tabs and Subtabs (Generally Available) :
    • LWC workspace API provides methods to manage workspace tabs and subtabs in Lightning Console App.
    • Import the lightning/platformWorkspaceApi module to access the LWC Workspace API methods, wire adapters, and event-based APIs via Lightning Message Service.
    • Below API methods for LWC are available for Lightning console apps.
      • closeTab() – Closes a workspace tab or subtab.
      • disableTabClose() – Prevents a workspace tab or subtab from closing.
      • focusTab() – Focuses a workspace tab or subtab.
      • getAllTabInfo() – Returns information about all open tabs.
      • getFocusedTabInfo() – Returns information about the focused workspace tab or subtab.
      • getTabInfo() – Returns information about the specified tab.
      • openSubtab() – Opens a subtab within a workspace tab. If the subtab is already open, the subtab is focused.
      • openTab() – Opens a new workspace tab. If the tab is already open, the tab is focused.
      • refreshTab() – Refreshes a workspace tab or a subtab specified by the tab ID.
      • setTabHighlighted() – Highlights the specified tab with a different background color and a badge. Tab highlights don’t persist after reloading a Lightning console app.
      • setTabIcon() – Sets the icon and alternative text of the specified tab.
      • setTabLabel() – Sets the label of the specified tab.
    • These wire adapters are available for Lightning console apps.
      • EnclosingTabId() – Returns the ID of the enclosing tab.
      • IsConsoleNavigation() – Determines whether the app it’s used within uses console navigation.
    • For more details check release notes
  • Lightning Record Picker Component (Generally Available) :
    • Use the lightning-record-picker component so that users can quickly find and select Salesforce records.
    • Use filter attribute to specifies which records the component lists in the record picker.
    • Supports retrieve up to 100 records.
    • For more details check Salesforce documentation
<lightning-record-picker
    label="Select a record"
    placeholder="Search..."
    object-api-name="Account"
    value={initialValue}
    onchange={handleChange}
></lightning-record-picker>

Apex : Salesforce has introduce new Apex features with new namespace.

  • Use the 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.
    • The null coalescing operator (??) replaces verbose and explicit checks for null references in code.
    • For more details check release notes
    • Example :
Integer notNullReturnValue = (anInteger != null) ? anInteger : 100;

This can be rewrite with Null Coalescing Operator as - 

Integer notNullReturnValue = anInteger ?? 100;
  • Get Support for Randomly Generated UUID v4 :
    • Use the new UUID class to generate a version 4 universally unique identifier (UUID)
    • For more details check release notes
UUID randomUuid = UUID.randomUUID();
  • Make Callouts After Rolling Back DML and Releasing Savepoints :
    • Use the new Database.releaseSavepoint method to explicitly release savepoints before making a desired callout.
    • 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.
    • For more details check release notes
    • Sample code where the makeACallout() callout succeeds because the uncommitted DML is rolled back and the savepoint is released.
Savepoint sp = Database.setSavepoint();
try {
	// Try a database operation
	insert new Account(name='Foo');
	integer bang = 1 / 0;
} catch (Exception ex) {
	Database.rollback(sp);
	Database.releaseSavepoint(sp); // Also releases any savepoints created after 'sp'
	makeACallout(); // Callout is allowed because uncommitted work is rolled back and savepoints are released
}
  • Compress and Extract Zip Files in Apex (Developer Preview) :
    • Use new Compression namespace methods to generate and compressed zip files.
    • Compress multiple attachments or documents as an Apex blob that contains the zip archive.
    • Use to extract data from the zip archive without uncompressing the entire zip archive.
    • For more details check release notes and Salesforce documentation
    • Sample code to compresses email attachments into a single file.
Compression.ZipWriter writer = new Compression.ZipWriter();

List<id> contentDocumentIds = new List<id>();

// Add IDs of documents to be compressed to contentDocumentIds 
for(ContentVersion cv : [SELECT PathOnClient, Versiondata 
							FROM ContentVersion 
							WHERE ContentDocumentId IN :contentDocumentIds]) 
{
	writer.addEntry(cv.PathOnClient, cv.versiondata);
}

blob zipAttachment = writer.getArchive();

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachments.zip');
efa.setBody(zipAttachment);

List<Messaging.EmailFileAttachment> fileAttachments = new List<Messaging.EmailFileAttachment>();
fileAttachments.add(efa);

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

// Set all the other email fields, such as addresses, subject, and body

email.setFileAttachments(fileAttachments);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email }); 
  • Evaluate Dynamic Formulas in Apex (Developer Preview) :
    • Use new FormulaEval namespace methods to evaluate user-defined dynamic formulas for Apex objects and SObjects.
    • Avoid unnecessary DML statements to recalculate formula field values or evaluate dynamic formula expressions.
    • For more details check release notes and Salesforce documentation
    • Sample Code uses build() and evaluate() methods
global class MotorYacht {
	global Integer lengthInYards;
	global Integer numOfGuestCabins;
	global String name;
	global Account owner;
}

MotorYacht aBoat = new MotorYacht();
aBoat.lengthInYards = 52; 
aBoat.numOfGuestCabins = 4;
aBoat.name = 'RV Foo';
FormulaEval.FormulaInstance isItSuper = FormulaEval.FormulaBuilder.builder()
                            .withReturnType(FormulaEval.FormulaReturnType.STRING)
                            .withType(MotorYacht.class)
                            .withFormula('IF(lengthInYards < 100, "Not Super", "Super")')
                            .build();
isItSuper.evaluate(aBoat); //=> "Not Super"

aBoat.owner = new Account(Name='Acme Watercraft', Site='New York');
FormulaEval.FormulaInstance ownerDetails = FormulaEval.FormulaBuilder.builder()
                            .withReturnType(FormulaEval.FormulaReturnType.STRING)
                            .withType(MotorYacht.class)
                            .withFormula('owner.Name & " (" & owner.Site & ")"')
                            .build();
ownerDetails.evaluate(aBoat); //=> "Acme Watercraft (New York)"

References :