Advanced SOQL Statements : In our previous Salesforce Tutorial we have learned about how to filter multipicklist values using SOQL queries. In this Salesforce Training Tutorial we are going to learn about advanced SOQL statements like what are the different SOQL escape sequences, SOQL date formats and SOQL date literals.

What is an escape sequence ?

An escape sequence character is a character that invokes an alternative interpretation of the subsequent characters in a character sequence.

Some of the escape sequence characters are as follows.

  1. \n or \N  – New line.
  2. \r or \R  – Carriage return.
  3. \t or \T  – Tab.
  4. \f or \F  – Form feed.
  5. \b or\B  – Bell.
  6. \”  – One double-quote character.
  7. \’  – One single-quote character.
  8. \\  – Backslash.
  9. The LIKE operator expression : \_  – It matches a single underscore character (_).
  10. The LIKE operator expression : \%  – Matches s single percentage a sign character (%).

SOQL Date Formats

When SOQL statements we should follow some date formats which are predefined in salesforce. There are four types of date formats in Salesforce object Query language. They are.

DATE FORMATEXAMPLES
YYYY-MM-DD2014-06-28
YYYY-MM-DD Thh:mm:ss+hh:mm2014-06-28 T23:01:01+01:00
YYYY-MM-DD Thh:mm:ss-hh:mm2014-06-28 T23:01:01+01-08:00
YYYY-MM-DD Thh:mm:ssZ2014-06-28 T23:01:01Z

SOQL Date literals.

There are different types of SOQL Date literals are present when querying the records using the date fields in the SOQL statements the date literals can be used. Some of the Date literals are as given below.

  1. YESTERDAY.
  2. TODAY.
  3. TOMORROW.
  4. LAST_WEEK.
  5. NEXT_WEEK.
  6. LAST_MONTH.
  7. THIS_MONTH.
  8. NEXT_MONTH.
  9. LAST_90_DAYS.
  10. NEXT_90_DAYS.
  11. LAST_N_DAYS:n.
  12. NEXT_N_DAYS:n.
  13. THIS_QUARTER.
  14. NEXT_QUARTER.
  15. NEXT_N_QUARTER:n.
  16. LAST_N_QUARTERS:n.
  17. THIS_YEAR.
  18. LAST_YEAR.
  19. NEXT_YEAR.
  20. NEXT_N_YEARS:n.
  21. LAST_N_YEARS:n.
  22. THIS_FISCAL_QUARTER.
  23. LAST_FISCAL_QUARTER.
  24. NEXT_FISCAL_QUARTER.
  25. NEXT_N_FISCAL_QUARTERS:n.
  26. LAST_N_FISCAL_QUARTERS:n.
  27. THIS_FISCAL_YEAR.
  28. LAST_FISCAL_YEAR.
  29. NEXT_FISCAL_YEAR.
  30. NEXT_N_FISCAL_YEAR:n.
  31. LAST_N_FISCAL_YEARS:n.