Skip to content

Salesforce Hack: An Introduction to SOQL using Salesforce’s Developer Console

 

Salesforce Admin Tips
Salesforce’s Reports are truly an incredible feature that are at the Salesforce Admin’s disposal. To be able to query and gain insight into your data as well as present data in visual form to management is every Admin’s dream. At times, however, I have found Salesforce’s Reports to be clunky and limited. For example, when running diagnostic reports and chasing an anomaly in our Salesforce data, I find Salesforce’s Reports interface slow to work with. It’s at moments like this that I turn to my favorite Salesforce tool – the Developer Console.

The Developer Console

One of the many reasons why the Developer Console is used is to run SOQL queries. SOQL (Salesforce Object Query Language) is Salesforce’s native language, based on the widely used Structured Query Language (SQL), for searching your organization’s data for specific information. SOQL is easy to learn, as it is similar to the English language as we speak it, and very useful. For this reason, it’s definitely worth every Salesforce Admin’s time to learn this language. In this blog, I will give you a short introduction into the Developer Console and the SOQL language. In order to open and start using the Developer Console, follow the simple steps below: In Salesforce, click on your user’s name located in the top right hand side of the page Capture1 Click on Developer Console (If you cannot see this option, it may be due to access rights. Please refer to the following link: https://help.salesforce.com/HTViewHelpDoc?id=code_system_log.htm) At this point, you should see the Console pop open. In this blog, we will focus on Salesforce’s query language (SOQL) so click on the tab named “Query Editor” located at the bottom of the Console. Capture2 You are now ready to start querying your Salesforce data. Copy the text below and paste it in the editor section of the Developer Console, as demonstrated in the screen shot: Select id, name, email, createddate from Contact where createddate = LAST_N_DAYS:90 Capture3 Now, click on “Execute” located in the bottom left hand side of the Developer Console. On executing the query above, you should see your result displayed in a table with the total number of rows displayed as the table header. It is not too hard to guess what you have just performed, you have asked your Salesforce database and received the Id, name, email address and creation date of all the contacts that have been created in the last 90 days. (If you do not see any results displayed, it is because no Contacts have been created in the last 90 days. Simply create a test Contact in Salesforce and Execute the query again. You should see the new Contact’s information displayed) The query used above is what is known as a select statement. It is used to select data from Salesforce database. To break the query down into digestible chunks: “select” is a command keyword used to retrieve the fields of an object. “id, name, email, createddate” are the name of the Object fields we want to retrieve, always separated by comma. “from Contact” tells Salesforce which object we would like to query, Contact in this case. “where createddate = LAST_N_DAYS:90” is known as the where clause, this is the filter in our dataset, used so that we only retrieve a specific set of data, not every single row of data in our database. I will leave you with the following query and seriously recommend that you take the time to dive into the world of SOQL, it is truly a powerful tool provided by Salesforce. Select account.name, count(id) from contact group by account.name order by count(id) desc The query above gets you the name of all accounts in your database with the number of contacts per account, ordered from highest to lowest. To expand your knowledge of SOQL, refer to Salesforce’s brilliant documentation, referenced below: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/ Enjoy the Salesforce Hack!

Soroosh Avazkhani

Junior Developer at Ebsta. Obsessed with finding and sharing all the best Salesforce Admin hacks to help you achieve Salesforce greatness!

Related Posts

Give your Sales Reps access to the best data

Long gone are the days where you had to rely on your Reps to add emails or data into Salesforce. Ebsta does it automatically. Reps now have access to 100% data accuracy without having to do a thing.
Find out more