Posts

Showing posts from November, 2018

Salesforce Apex: If else statements vs Switch statements

In this article, we will compare the performance of If else statements vs the Switch statements available in Apex. Switch statements was a long awaited feature in Apex and Salesforce released the Switch statements in the Summer '18 release. This article will help the developers to decide whether to use the traditional If else statements or to go with the newly introduced Switch statement. I have done a simple test to compare the performance of both. The test involves querying the Account records, along with an inner query to fetch the related contacts and then iterating over them in a loop. The first test uses the If else statements and the second test uses the Switch statement. Performance of If else statement: List<Account> accList = [SELECT Name,(SELECT Name FROM Contacts) FROM Account]; System.debug('Start Time: '+Limits.getCpuTime()); Integer i = 0; for(Account acc: accList){     if(i == 0){         System.debug('Account List: '+accList);    

Salesforce Lightning: Global Search

Image
Today we will have a look at creating a custom global search using Lightning and SOSL. We will use SOSL to query the results from database and show it on the lightning component using the lightning:datatable tag SOSL is preferred over SOQL in use cases where we want to search for a particular keyword across different objects. The return type of SOSL will be a list of list of sobjects.  List<List<sObject>> searchResult = [FIND :searchKey                                             IN ALL FIELDS RETURNING                                             Account (Id, Name, AccountNumber, Website),                                             Contact(Id, Name, Email, MobilePhone),                                             Opportunity(Id, Name, StageName, CloseDate),                                             Lead(Id, Name, Email, Company)]; Lightning datatable was introduced by Salesforce in Winter 18 release. With lightning datatable, now it has become very easy to