Category: Winter21

How to use Safe Navigation Operator (?.) in Apex | Winter 21 New Feature

 Salesforce rolled out a new feature in Winter 21 release, it’s called – SAFE NAVIGATION. Safe navigation operator is a very useful syntax for Salesforce Developers and it will make the coding clean. The main purpose of this syntax is to avoid null pointer exceptions.Basic SyntaxString accountName = accountRecord?.Name;The above statement will store accountRecord.Name value in the variable accountName. As you can understand that accountRecord is basically the sObject variable holding Account record and then we are using that variable to fetch the Name property. Now, what will happen if the accountRecord is null, then null.Name will definitely give the null pointer exception, right? But the answer is No. Because we have used the safe navigation operator(?.) here. Safe navigation operator will make the check and if the accountRecord is not null, then only store the Name field to accountName, otherwise, it will just store null there.How it works:If the left side of the chain expression (?.) evaluates to null, then the right side will not be evaluated. This safe navigation can be used in the method, variable, and property chaining. The part of the expression that is not evaluated can include variable and property chaining.Example 1:Let’s say we have a method that will take the AccountNumber as a parameter and print the AccountName.Before Winter 21 without Safe Navigation, our code will look like –    public static void getAccountNameWithoutSafeNavigation(String accountNumber){...

Read More

Send Custom Notifications Using Apex

Winter 21 release is bringing many great features for us. We are all excited. Here are some of my posts covering some of the important features that will come with the Winter 21 release -Winter 21 Admin New FeaturesWinter 21 Apex New FeaturesWinter 21 Flow EnhancementsIn today’s post, I will be discussing about the feature which will allow us to send custom notifications using Apex. Introduction of Custom NotificationCustom notifications are the customized notifications that can be sent when some action happened with Salesforce. For example, every time a new knowledge article is published, we can publish a custom notification to all the users/selected users. These notifications are real-time i.e. users don’t require to refresh their existing page to get the notification. On the same only, these notifications will be presented on the bell icon.Create Custom NotificationType ‘Notification’ in the setup searchClick ‘Custom Notifications’ under ‘Notification Builder’Click NewEnter the name for example – “Knowledge Notification”Select the channels (Mobile and/or Desktop).Apex Code to Send Notification//New Class introduced to deal with Custom NotificationsMessaging.CustomNotification singleNotification =                         new Messaging.CustomNotification();//Required – Setting up the BodysingleNotification.setBody(‘New Article is published’);//Required – Setting up the titlesingleNotification.setTitle(‘Check the new article!’);//Optional – Who is sending this notificationsingleNotification.setSenderId(Userinfo.getUserId());//Fetching the custom notification created and using that idCustomNotificationType type = [ SELECT Id                                 FROM CustomNotificationType               ...

Read More

New Admin Features From Winter 21 Release

In today’s post, I am going to share some of my favorite Admin features from Winter 21 release.SurveyWhile creating the survey, admins now have the option of saving the survey as a template. After creating the template, users can open it and make a copy from the top-right menu to create their own survey based on the template.Flow EnhancementsI have written a separate post covering only flow enhancements coming with Winter 21 release.Here is the post – Winter 21 Flow EnhancementsDynamic Form    With this release, admins now have the power to select the position of the fields in the page layout. As of today, this is only available to custom objects and Lightning App Builder.When admins will open the record details section from the Lightning page in App Builder, they will be presented with the option to Upgrade (as shown below). Selecting the upgrade option will provide the admins the option to create dynamic forms by positioning fields in different sections on the layout.Even admins can click on the “Analyze” button at the top right section which will provide them the option whether the customization is good from a performance standpoint.No More Ref IDs in Email-to-CaseRef IDs are not always our good friend when dealing with Email-to-Case, as people tend to delete, modify those ugly looking ids when sending emails/replies and that always causes problems with case routing.The good...

Read More

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

Winter ’21 Flow Enhancements

 Winter ’21 pre-release org is ready. And without any surprise, Winter ’21 is also bringing lots of great enhancements. In this post, I am going to focus on a few Flow Enhancements that we will be getting soon and will be able to take advantage of. Handling Deletion Through Record Triggered FlowWith Winter ’21, we will be able to trigger a flow when the record is getting deleted. This is similar to Delete context from Trigger. To me, this is a great enhancement. Few things to note, you can. only do Before the record is deleted, not after the record is deleted. And if the deleted record is recovered later, that will not rollback any changes/actions performed as part of the flow. To handle that situation, the recommended approach is to write Apex after undelete trigger.Auto LayoutsWith this release, you will be presented with the option of selecting either a Freeform or Autolayout option. Autolayout is in Beta stage right now. But if you select Autolayout, you basically keep adding components by clicking on + sign. No need to organize and dragging here and there to make the flow look good, keep the connector line straight, etc. If you are like me, who likes to see things organized, I am sure you will like this feature as well.Debug Flow as Specific UserIf you feel frustrated with the complaint that flow...

Read More
Loading