Category: developer

Fetch All Fields In SOQL Query | Spring 21 New Feature

 If you worked with SQL or any other query language before, you probably familiar with Select * from …, right? This is the way to fetch all fields from a particular table in other(mostly all) query languages. But in the Salesforce world, we were not having this feature. In SOQL, there is nothing with which we can fetch all the fields unless we specifically mention all the field names in the query.But now in Spring 21, Salesforce is bringing a function through which we can fetch all fields in SOQL Query.We have now FIELDS(ALL), FIELDS(STANDARD), and FIELDS(CUSTOM) which we can use in the SOQL query.FIELDS(ALL) – This fetches all the fields of an object. This is similar like Select * from SQL.FIELDS(STANDARD) – This fetches all standard fields of an object.FIELDS(CUSTOM) – This fetches all custom fields of an object.Here is how the query will look like -List<Contact> allConatcts = [SELECT FIELDS(ALL) FROM CONTACT LIMIT 200];In Subqueries, it will look like -List<Account> allAccounts = [ SELECT Account.Name, (SELECT FIELDS(ALL) FROM Account.Contacts LIMIT 200) FROM Account];BOUNDED AND UNBOUNDED QUERIESWhen API cannot determine the set of fields in advance, then it will consider query as Unbounded Query, other if API can determine the set of fields in advance, then it is Bounded Query. For example – The number of custom fields for an object is not pre-determined, so FIELDS(CUSTOM) and FIELDS(ALL)...

Read More

SOQL Query Builder in VS Code, the fastest way to write SOQL statements

Salesforce introduced the fastest way to write SOQL statements, the SOQL Query Builder. SOQL Query Builder is the Visual Studio Code Extension that enables you to write, execute SOQL statements write inside your project workspace. Not only that, this tool will allow you to download the query result in either CSV or JSON format.How to install SOQL Query BuilderOnce you open the Visual Studio Code, search for SOQL in Marketplace. From there install the SOQL extension from Salesforce. After installation, it is always recommended to restart VS Code. Below is the screenshot How to use SOQL Query BuilderAfter installation, all your soql files will be stored under the folder scripts -> soql. You can save your own soql commands, just make sure the extension of the file is .soql.Below is the example where I have opened account.soql file and executed the statement. As you can see, with this new tool, we have the opportunity to do everything we are doing today with workbench w.r.t. executing soql statements. Also, you can download the query result in either CSV or JSON format.Youtube VideoVideo Link: https://www.youtube.com/watch?v=LG13jPWYqVwReference...

Read More

Advanced Currency Management in Salesforce

Salesforce supports multi currency. You can enable the same by going to Company Information and then checking the box – “Activate Multiple Currencies”. You need to read the below article before enabling multi currency. https://help.salesforce.com/articleView?id=admin_enable_multicurrency_implications.htmOnce done, you can enable Dated Exchange Rate to define the exchange rate for any kind of periods like month, quarter, year etc. To do that you can go to Company profile -> Manage CurrenciesNow you can add the entries for dated exchange rates by clicking on the “Manage Dated Exchange Rates” button. And then click on “New Exchange Rates” button. Below images shows how to add dated exchange rates.This dated exchange rates are used in Opportunities, Opportunity products and Opportunity Reports.The object used to store this information is DatedConversionRate. You can run SOQL queries against this object to get the details -SELECT IsoCode,ConversionRate,NextStartDate,StartDate FROM DatedConversionRate ORDER BY NextStartDate ASCYou can use Rest Explorer also to add/delete new DatedConversionRate like below -Important Objects/Fields:CurrencyType: This object stores the list of currencies used in the org when multi currency is enabled. If single currency is used in the org, then this object is not available.DatedConversionRate: This object stores the dated exchange rates.CurrencyIsoCode: This additional field is present in object which has current field and the org has multi-currency...

Read More

Switch Statement in Apex – Long Pending Must To Have Feature

Finally we have Switch statement in Apex. Like me, I am very much sure there are many developers who were waiting for this feature. Salesforce introduced Switch statement in Winter’18 release.In this post I am going to share few important stuffs that developer should keep in mind while using Switch.Let me start with a very basic example.In the above code I am using Switch statement. But did you notice that Switch statement in Apex is little different than traditional Switch statement in Java or C programming language?No Case Statement: We don’t have case statement in Apex programming language. Reason behind is that Case is a sObject in Apex. That is why Salesforce is having when keyword.No Break: In Apex, we don’t have break statement like we used to have in C programming language. The reason is that in Apex, there is no fall-through. It means unlike C, the first executed branch will block any following branch in Switch statement. For example, if you execute the above code with parameter ‘India’, it will only print I am in India. It will not execute other System.Debug statements.sObject support: Apart from standard String, Integer, Long support, Switch statement in Apex can support sObject as well. To illustrate that, consider the below use case -When a Task is getting created, it can be associated with many sObjects like Account or Case. So based...

Read More

Query Plan Tool from Salesforce – A Hidden Gem

Query Plan in the developer console can help to speed up SOQL queries done over large volumes of data. This is such a powerful tool when dealing with bad performance. Developer can use this tool to optimize and speed up SOQL queries.We can enable Query Plan in the Developer Console by -Before we go into details, it’s better to understand how Salesforce uses indexes while running the SOQL. As we all know it is always good to go for selective query instead of full table scan. But even with selective query, when we are using different filter criteria, it is not always the best SOQL query we are writing. The reason behind is that just writing where clause in the query does not guarantee that the filter is selective. So it is very important to understand which are the fields are good to be used in filter. Let’s understand that first in the below section -All we need to use is the indexes in the filter.If we are using filter on standard fields, then we are using index if -it is primary key (Id, Name, OwnerId)it is a foreign key (CreatedById, LastModifiedById, Lookup, Master-Detail)it is an audit field (CreatedDate, SystemModstamp).If we are using filter on custom fields, then we are using index if that field is marked as Unique or External Id.Without indexed filter, the query will not be...

Read More
Loading