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.
- \n or \N – New line.
- \r or \R – Carriage return.
- \t or \T – Tab.
- \f or \F – Form feed.
- \b or\B – Bell.
- \” – One double-quote character.
- \’ – One single-quote character.
- \\ – Backslash.
- The LIKE operator expression : \_ – It matches a single underscore character (_).
- 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 FORMAT | EXAMPLES |
YYYY-MM-DD | 2014-06-28 |
YYYY-MM-DD Thh:mm:ss+hh:mm | 2014-06-28 T23:01:01+01:00 |
YYYY-MM-DD Thh:mm:ss-hh:mm | 2014-06-28 T23:01:01+01-08:00 |
YYYY-MM-DD Thh:mm:ssZ | 2014-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.
- YESTERDAY.
- TODAY.
- TOMORROW.
- LAST_WEEK.
- NEXT_WEEK.
- LAST_MONTH.
- THIS_MONTH.
- NEXT_MONTH.
- LAST_90_DAYS.
- NEXT_90_DAYS.
- LAST_N_DAYS:n.
- NEXT_N_DAYS:n.
- THIS_QUARTER.
- NEXT_QUARTER.
- NEXT_N_QUARTER:n.
- LAST_N_QUARTERS:n.
- THIS_YEAR.
- LAST_YEAR.
- NEXT_YEAR.
- NEXT_N_YEARS:n.
- LAST_N_YEARS:n.
- THIS_FISCAL_QUARTER.
- LAST_FISCAL_QUARTER.
- NEXT_FISCAL_QUARTER.
- NEXT_N_FISCAL_QUARTERS:n.
- LAST_N_FISCAL_QUARTERS:n.
- THIS_FISCAL_YEAR.
- LAST_FISCAL_YEAR.
- NEXT_FISCAL_YEAR.
- NEXT_N_FISCAL_YEAR:n.
- LAST_N_FISCAL_YEARS:n.