Salesforce Object Query Language

Image for post
Image for post

SOQL stands for Salesforce Object Query Language and it is the language that is used to search your organizations Salesforce data for specific information. It is very similar to the SELECT statement in the popular Structure Query Language (SQL).

SOQL Disadvantages

No Wild Cards

SOQL does not support many of the advanced features that SQL does. For example you can not use the wild card (*) operation to bring back a list of all your records. This means you can’t do the following:

SELECT * FROM Table_Name;

No Join Operations

You cannot perform join operations (left join, right join, etc..) For example:

SELECT name FROM Table_A A RIGHT JOIN Table_B B ON A.key = B.key

No Arithmetic Operations

You cannot perform arithmetic operations . For Example:

SELECT 15 + 5 FROM dual;

SOQL SELECT Syntax

SOQL query syntax consists of a required SELECT statement followed by one or more optional clauses, like TYPEOF, WHERE, WITH, GROUP BY, and ORDER BY.

The SOQL SELECT statement uses the following syntax:
SELECT fieldList [subquery][…]
[TYPEOF typeOfField whenExpression[…] elseExpression END][…]
FROM objectType[,…]
[USING SCOPE filterScope]
[WHERE conditionExpression]
[WITH [DATA CATEGORY] filteringExpression]
[GROUP BY {fieldGroupByList|ROLLUP (fieldSubtotalGroupByList)|CUBE (fieldSubtotalGroupByList)}
[HAVING havingConditionExpression] ]
[ORDER BY fieldOrderByList {ASC|DESC} [NULLS {FIRST|LAST}] ]
[LIMIT numberOfRowsToReturn]
[OFFSET numberOfRowsToSkip]
[FOR {VIEW | REFERENCE}[,…] ]
[ UPDATE {TRACKING|VIEWSTAT}[,…] ]

The SELECT statement above looks overwhelming, I won’t go that deep into SOQL in this article. We will write some simple SOQL statements to ease our way into this language. You can check out the video below to see how you can query data in Salesforce.com:

SOQL SELECT Statement Examples

Simple SELECT statement
This query returns all names, phone numbers, and account numbers from the Account object

SELECT Name, Phone, accountNumber, Site FROM Account

SELECT statement with a WHERE clause
This query returns the name , phone numbers , account numbers, and sites from the account object whose account name is ‘sForce’

SELECT Name, Phone, accountNumber, Site FROM Account WHERE name = 'sForce'

SELECT statement with a WHERE and LIKE clause using the ‘%’ wild card
This query returns the id, name, billing city, and phone number from the account object that have account names that start with ‘United’

SELECT id, name Billingcity, phone FROM Account WHERE name like 'United%'

SELECT statement to bring back only 3 rows of data in descending order
This query returns the id, name , billingcity, and phone number from the account object ordered in descending order (From least to greatest) , and brings back only the first 3 rows.

SELECT id, name, Billingcity, phone FROM Account ORDER BY name DESC LIMIT 3

You can check out the video below to see how you can query data in Salesforce.com:

Thanks for reading this article I hope its helpful to you all ! Keep up the learning, and if you would like more computer science, programming, Salesforce and algorithm analysis videos please visit and subscribe to my YouTube channels (randerson112358 & compsci112358 )

If you are interested in learning more about Salesforce check out Salesforce.com for Dummies, it has a lot of good information about the platform.

Image for post
Image for post
Salesforce.com for Dummies
Image for post
Image for post

Check Out the following for content / videos on Computer Science, Algorithm Analysis, Programming and Logic:

YouTube Channel:
randerson112358: https://www.youtube.com/channel/UCaV_0qp2NZd319K4_K8Z5SQ

compsci112358:
https://www.youtube.com/channel/UCbmb5IoBtHZTpYZCDBOC1CA

Website:
http://everythingcomputerscience.com/

Video Tutorials on Recurrence Relation:
https://www.udemy.com/recurrence-relation-made-easy/

Video Tutorial on Algorithm Analysis:
https://www.udemy.com/algorithm-analysis/

Twitter:
https://twitter.com/CsEverything

YouTube Channel:

Image for post
Image for post

Computer Science Website:

Image for post
Image for post

Udemy Videos on Algortithm Analysis:

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store