Spring 21 is bringing a couple of Apex features that can be definitely helpful. This post will cover a few of my favorite Apex features from Spring 21.
With Spring 21, we can fetch the entire custom metadata records or a single record from the custom metadata. So no more SOQL query to fetch custom metadata records. Here is the video where I have explained the feature.
With getAll() method, now we can get the entire custom metadata records. Here is the small code snippet
With getInstance( recordId ), getInstance( qualifiedApiName ), getInstance( developerName ) method, now we can get the single custom metadata record. Here is the small code snippet
By making the callout attribute true, you are basically telling Salesforce to take the decision (best decision) whether to run the callout in the currently running transactions or in a new transaction.
With the callout attribute set to false, action will always happen in the current transaction whether the transaction has uncommitted work, which can cause some expected issues.
Feature #5
If the SOQL queries are having a for loop, then Apex will no longer generate or use the query cursor internally. Instead, records are buffered in memory for improved performance and reduced query cursor contention. Though this improvement is not applicable to Batch Apex queries.
Feature #6
Starting Spring 21, you can now convert leads into a Person and Business Account at the same time with the new LeadConvert methods. Note – This feature is only available in Lightning and in Enterprise, Performance, and Unlimited editions.
The Transaction Finalizers feature is in Beta as of Spring 21. Basically, Transaction Finalizer will make sure that any failed (due to some unhandled exceptions) Queueable job can be re-queued only for 5 times (that’s the new limit). The counter will reset when the Queueable job completes without an unhandled exception.