Query Languages & DML

Learn About Query Languages & DML in Salesforce

To fetch data, we have a query language in Salesforce. Below are the database query languages in Salesforce.

  • SOQL - Salesforce object query language
  • SOSL - Salesforce object search language

These two languages help us to deal with databases, to fetch needed data.

Why Do We Need Two Query Languages?

  • SOQL is used for fetching records based on some parameters or conditions. Example: get the records from a database where the country of the customer is India.
  • Query has some conditions. Table name. We are not doing any random table search. Everything has to be clearly mentioned.
  • SOSL is used for fetching some information from a database. Example: We want to write a code by which we can see records where the word “Peter” is used in the database. Search query will have a text to search.

dont miss out iconDon't forget to check out: An Ultimate Guide on How to Import Data in Salesforce

Aggregate Functions in Salesforce

  • SELECT MAX(Custom_Field__c) FROM Custom_Object__c
  • SELECT MIN(Custom_Field__c) FROM Custom_Object__c
  • SELECT SUM(Custom_Field__c) FROM Custom_Object__c
  • SELECT AVG(Custom_Field__c) FROM Custom_Object__c

Differences Between SOQL & SOSL

  • As the name suggests, SOSL is an object search language. This will search for some phrases or words for making developers find any record or data.
  • SOSL can search for something only in name, phone, email fields. Example: Something present in number, picklist or currency, we cannot search, means, if our data is present in the field of type name/phone/email, then only we can do searching.
  • Using SOSL we can make queries on many objects at a time.
  • We can query only on fields having type name, phone or email.
  • Using SOQL, we can make queries only on one object at a time.
  • We can query on all fields of any data type.

Joins in Salesforce

Salesforce does not support joins, where we can fire/call one query on multiple objects and get data, the way we can do in oracle, SQL etc.

Salesforce provides an alternate solution for this, which is called ‘Relationship queries’. This means those objects which are having relationships, we can fire “join like query” on them. They must be in relation.

dont miss out iconCheck out another amazing blog by Romil here: Triggers in Salesforce - Get Started

DML Statements

DML statements are called Data Manipulation Language. We can make changes in the database and commit the same by using statements like Insert-Update-Delete.

DML statements are so essential, that without this you can not make any changes to records in the database

By using Database queries like SOQL/SOSL, we can only fetch data. They won't help with making changes in data.


Popular Salesforce Blogs