Home Release Update Apex Enhancement in Salesforce Winter ’23

Apex Enhancement in Salesforce Winter ’23

by Dhanik Lal Sahni

Apex is used for business customization in Salesforce Application. Many new features are being added in the winter’23 release. This post will explain important Apex Enhancement in Salesforce Winter ’23.

1. Use DataWeave in Apex to Enable Data Transformation ( Developer Preview)

Many times we have to transform data in Apex. To transform data, We are supposed to create a custom wrapper class.

Salesforce added a new feature DataWeave in Winter 23 release. This feature enhances native Apex data transformation support by integrating Mulesoft’s DataWeave library into the Apex runtime. It makes data transformation easier to code, more scalable, and more efficient. With this feature, Apex developers can focus more on solving business problems and less on addressing the specifics of file formats.

The below example shows the transformation of an input CSV file into Contact sObject.

// CSV data for Contacts\n
String inputCsv = 'first_name,last_name,email\nCodey,"The Bear",codey@salesforce.com'; 
DataWeave.Script dwscript = DataWeave.Script.createScript('csvToContacts');
DataWeave.Result dwresult = dwscript.execute(new Map<String, Object>{'records' => inputCsv});
List<Contact> results = (List<Contact>)dwresult.getValue();

Assert.areEqual(1, results.size());
Contact codeyContact = results[0];
Assert.areEqual('Codey',codeyContact.FirstName);
Assert.areEqual('The Bear',codeyContact.LastName);

2. More Database Security with User Mode Code Execution

Apex code runs in system mode by default, which means that it runs with elevated permissions over the user running the code. To enhance the security context of Apex, we can specify user mode access for database operations. Field-level security (FLS) and object permissions of the running user are respected in user mode, unlike in system mode. User mode always applies sharing rules.

 Below new methods are added in this release.

  • Database.getQueryLocator methods
  • Database DML methods (deleteAsyncdeleteImmeidateinsertAsyncinsertImmediateupdateAsync, and updateImmediate)

3. Call Invocable Actions from Apex

New apex class Invocable.Action allows us to call invocable actions from Apex code.

For example, this class calls the standard invocable action “chatterPost” to post a message to the current user’s feed.


public class MyApexClass {
    public void postToChatter(String recordId) {
        Invocable.Action action = Invocable.Action.createStandardAction('chatterPost');
        action.setInvocationParameter('text', 'This is an example Chatter post.');
        action.setInvocationParameter('subjectNameOrId', recordId);
        List<Invocable.Action.Result> results = action.invoke();
        if (results.size() > 0 && results[0].isSuccess()) {
            System.debug('Created feed item with ID: ' +
            results[0].getOutputParameters().get('feedItemId'));
        }
    }
}

4. Limits on Concurrently Open Query Cursors are Removed

Currently, a user can have up to 10 query cursors open at a time. If 10 QueryLocator cursors are already opened and attempt to open a new one, then the oldest of the 10 cursors is released.

Now Query cursors open concurrently per user are no longer restricted in number.

References:

Salesforce Winter ’23 Release Notes

Related Posts

LWC Enhancement in Salesforce Winter ’23

Salesforce Flow Update in Salesforce Winter ’23

Data Transformation with DataWeave in Salesforce Apex

Other Useful Posts

Shopify integration with Salesforce using Webhook

Data Transformation with DataWeave in Salesforce Apex

Generic Multi-Select Lookup Component

Secure Apex Code with User Mode Operation

Data Table in Screen Flow

Multi Select Lookup in Screen Flow

You may also like

1 comment

Why and How to Pass the Salesforce Administrator Certification? - Salesforce Codex June 28, 2023 - 1:04 pm

[…] APEX ENHANCEMENT IN SALESFORCE WINTER ’23 […]

Reply

Leave a Comment

Top 10 Salesforce Service Cloud Features Top 10 Best Practices for Lightning Flow Facts and Statistics for Salesforce’s Size and Market Share Top 5 Contract Management Salesforce Apps Top 10 Enterprise Integration Use Cases