Salesforce provides development platform Force.com as Platform as a Service(PAAS) which is used to enhance functionality of Salesforce platform so from this tutorial we are going to learn how to customise Salesforce with our needs and build our own application using Force.com platform’s available tools. with this tutorial you will understand soql basic.
As we all know Salesforce is used to store customer data our first task to learn the query language so that we can extract information from the Salesforce database and user further in our application.
What is SOQL :
SOQL is Salesforce Object Query Language SOQL which allows you to specify the source object (such as Account, Contact), a list of fields to retrieve, and conditions for selecting rows in the source object. SOQL uses the SELECT statement combined with filtering statements to return sets of data, which may optionally be ordered.
a sample query
SELECT ID,NAME FROM ACCOUNT LIMIT 5
it is pretty simple, isn’t it? it is the same syntax which we use in other query language such as MYSQL, MSSQL.
Where to Write:
Salesforce Provides different way to execute your query, for now we are going to use a simplest one which is using developer console.
- Login to your Developer account using http://login.salesforce.com
-
Open Developer Console.
- Open Query editor as show in below screenshot
- Type Following query.
SELECT ID,NAME FROM ACCOUNT LIMIT 5
or
SELECT ID,NAME FROM contact LIMIT 5
or
SELECT ID,NAME FROM opportunity LIMIT 5
Great! isn’t it simple as
4. Writing Aggregate query:
SOQL provides different keyword for aggregation of records such as sum, min, max, count so write following query in developer console.
SELECT SUM(AMOUNT) FROM OPPORTUNITY WHERE AMOUNT>10000
OR
SELECT MAX(AMOUNT) FROM OPPORTUNITY
OR
SELECT MAX(AMOUNT) FROM OPPORTUNITY
OR
SELECT MIN(AMOUNT) FROM OPPORTUNITY LIMIT 5
Happy Coding!!!
Comments