Apex Salesforce Winter Release 21

We are going to go through all the apex update in release 21. its excited to see some best update from Salesforce this time and it will be reduce code size and complexity.

Salesforce provide some new way to express null pointer exception. We can send custom notification using Messaging.CustomNotification class. The Database.deleteImmediate()support batch deletes up to 50,000 big object records. Provide some error message on sObject like SObject.hasErrors() and SObject.getErrors(). We will discuss in brief for every update.

Please see the quick update from Salesforce in this release.

  1. Use the Safe Navigation Operator to Avoid Null Pointer Exceptions
  2. Send Custom Notifications from Apex
  3. Update Resources with the PATCH HTTP Method in Apex Callouts
  4. Detect Apex Runtime Context with RequestId and Quiddity
  5. Improve Apex Testing with New SObject Error Methods
  6. Delete up to 50,000 Big Object Records in a Batch
  7. Enhanced Support for @namespaceAccessible Annotation

I will try to elaborate few updates in this story with example.

Use the Safe Navigation Operator to Avoid Null Pointer Exceptions

This update is very interesting. after this update, Line of code will reduce and complexity also reduce. Sometime before we got error in static code analyze which says please reduce the if else element. This new operator (?.) return null instead of throwing a null exception in apex code.

Send Custom Notifications from Apex

Salesforce introduce new method for send custom notification from apex code. Such as a trigger. It use for avoids API callout and authentication complexity. It is very useful if you are sending notification from trigger or sending many notifications.

For Sending custom notification you have to follow following steps.

  1. Create notification type

Goto Setup > Search Notification Builder > Create and fill the required information.

2. Send Notification

For send Notification we can use following ways like Process builder, Flow, customNotificationAction Invocable Action, But I am going to use apex class for sending custom notification.

Update Resources with the PATCH HTTP Method in Apex Callouts

To make partial or full updates to a resource in an HTTP web service, specify the PATCH method in the HttpRequest class. Previously, only the PUT method was supported for full updates.

Improve Apex Testing with New SObject Error Methods

Basically this update for improve test class error methods. Salesforce introduce two new methods SObject.hasErrors() and SObject.getErrors(). This methods without performing a DML operation to check the result for errors.

Delete up to 50,000 Big Object Records in a Batch

The Database.deleteImmediate() method now supports batch deletes of up to 50,000 big object records at once. This new limit matches the total number of records you can retrieve with a SOQL query.

Enhanced Support for @namespaceAccessible Annotation

The @namespaceAccessible annotation provides enhanced support for accessing interfaces, properties, and abstract classes in second-generation packages.

Update Resources with the PATCH HTTP Method in Apex Callouts.

To make partial or full updates to a resource in an HTTP web service, specify the PATCH method in the HttpRequest class. Previously, only the PUT method was supported for full updates.

Note : I will try to add more more description and provide you demo when all the method available in apex developer guide. How and When to use!

Reference : https://releasenotes.docs.salesforce.com/en-us/winter21/release-notes/rn_apex.htm

Please provide your feedback for any type of correction.