Winter ’21 Apex New Feature
This post will cover some of my favorite Apex new features from Winter ’21. I have published another post that covered new existing enhancements for Flow Designer. To explore all the new features from Winter ’21 release, I highly recommend -Sign up to a pre-release org and explore all the new features.Post your findings in the Trailblazer Community and include the hashtag #Winter21Treasure to receive Trailhead Treasure Hunter badgeHere is the listSafe Navigation OperatorWith the introduction of Safe Navigation operator (?.), we are no more needed to perform an explicit null check to avoid NullPointer Exception. Basically, if the left side expression of the operator evaluates to null, then the right side will not be evaluated. //Before Winter’21List<Contact> allContacts = [ SELECT Id FROM Contact WHERE name = :contactName];if (allContacts.size() > 0) { String Id = allContacts.get(0).Id;}//After Winter’21String Id = [SELECT Id FROM Contact WHERE name = :contactName]?.get(0).Id;Update Resources with the PATCH HTTP Method in Apex CalloutsBefore Winter ’21 it was not possible to make a PATCH request from Salesforce. We always used the hack of using the PUT method to make it work. But with Winter ’21 we can now make PATCH metho in our HttpRequest class.Detect Apex Runtime Context with RequestId and QuiddityNow it is possible to detect Apex context at runtime and correlate multiple logs triggered by the request, using Request ID and Quiddity values.//Get info about...
Read More