SOQL & SOSL - Chirag-ahir/SFC-Preparation GitHub Wiki

SOQL: Salesforce Object Query Language

SOQL is used to query data from Salesforce objects. It allows you to specify the fields, criteria, and order in which data should be returned.

SELECT Id, Name, Email FROM Contact WHERE Account.Name = 'Acme Corp' ORDER BY LastName

Key Features:

  • Structured Query: SOQL is similar to SQL but tailored for Salesforce's data model. It supports SELECT statements to retrieve data.
  • Field Selection: You can specify which fields to retrieve.
  • Filtering: You can use WHERE clauses to filter records based on criteria.
  • Ordering: You can use ORDER BY to sort the results.
  • Relationships: You can query parent-to-child and child-to-parent relationships using dot notation and nested queries.

SOSL: Salesforce Object Search Language

SOSL is used to perform text searches in Salesforce. It allows you to search across multiple objects, fields, and records.

FIND {Acme} IN Name, Company IN Account, Contact RETURNING Account(Id, Name), Contact(Id, Name, Email)

Key Features:

  • Text Search: SOSL is optimized for searching text within records.
  • Multiple Objects: You can search across different Salesforce objects in a single query.
  • Multiple Fields: It searches across all specified fields in the objects.
  • Flexible Matching: It supports partial matches and wildcards.

Differences:

  • Scope: SOQL is more like a database query language, focusing on retrieving data with specific criteria. SOSL is a search language, focusing on finding records with matching text.
  • Use Cases: Use SOQL when you need to retrieve specific data and relationships. Use SOSL when you need to perform a text search across multiple objects and fields.

SOSL Guide: https://mindmajix.com/sosl-of-salesforce

Where can you write SOQL & SOSL?##

  1. You can write query in developer console of salesforce

image

  1. You can use workbench also to generate SOQL & SOSL query

https://workbench.developerforce.com/login.php

image