Difference between SOQL and SOSL in Salesforce

SOQL in Salesforce

  • SOQL  stands for”Salesforce Object Query Language”.
  • It returns Records.
  • Records are stores in collection. Records are pertaining to single sObject.
  • Search in single sObject and it retains records.
  • SOQL retrieves the data from the database using “SELECT” keyword.
  • It works on multiple objects at the same time.
  • SOQL is not used in Triggers and can be used only in Apex classes and anonymous block.
  • SOQL against the same field will be slow.
ADVERTISEMENT

SOSL in Salesforce

  • SOSL stands for “Salesforce Object Search language”.
  • It returns fields.
  • Records are pertaining to different sObjects.
  • Search in entire Org and returns fields.
  • SOSL retrieves the data from the database using the keyword “FIND“.
  • It doesn’t work on multiple objects at the same time and need to write different SOQL queries for different objects.
  • SOSL can be used in Triggers and Apex class.
  • All fields are already text indexed.