SOQL and SOSL Reference
Total Page:16
File Type:pdf, Size:1020Kb
SOQL and SOSL Reference Version 53.0, Winter ’22 @salesforcedocs Last updated: August 26, 2021 © Copyright 2000–2021 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc., as are other names and marks. Other marks appearing herein may be trademarks of their respective owners. CONTENTS Chapter 1: Introduction to SOQL and SOSL . 1 Chapter 2: Salesforce Object Query Language (SOQL) . 3 Typographical Conventions in This Document . 5 Quoted String Escape Sequences . 5 Reserved Characters . 6 Alias Notation . 7 SOQL SELECT Syntax . 7 Condition Expression Syntax (WHERE Clause) . 9 fieldExpression Syntax . 13 USING SCOPE . 26 ORDER BY . 27 LIMIT . 28 OFFSET . 29 FIELDS() . 31 Update an Article’s Keyword Tracking with SOQL . 35 Update an Article Viewstat with SOQL . 35 WITH filteringExpression . 35 GROUP BY . 40 HAVING . 47 TYPEOF . 48 FORMAT () . 51 FOR VIEW . 51 FOR REFERENCE . 52 FOR UPDATE . 52 Aggregate Functions . 53 Date Functions . 58 Querying Currency Fields in Multi-Currency Orgs . 60 Example SELECT Clauses . 62 Relationship Queries . 63 Understanding Relationship Names . 64 Using Relationship Queries . 65 Understanding Relationship Names, Custom Objects, and Custom Fields . 66 Understanding Query Results . 68 Lookup Relationships and Outer Joins . 70 Identifying Parent and Child Relationships . 70 Understanding Relationship Fields and Polymorphic Fields . 72 Understanding Relationship Query Limitations . 77 Using Relationship Queries with History Objects . 77 Contents Using Relationship Queries with Data Category Selection Objects . 78 Using Relationship Queries with the Partner WSDL . 78 Change the Batch Size in Queries . 78 SOQL Limits on Objects . 79 SOQL with Big Objects . 83 Syndication Feed SOQL and Mapping Syntax . 84 Location-Based SOQL Queries . 84 Async SOQL . 88 Chapter 3: Salesforce Object Search Language (SOSL) . 91 Typographical Conventions in This Document . 93 SOSL Limits on Search Results . 93 SOSL Limits on External Object Search Results . 95 SOSL Syntax . 95 Example Text Searches . 98 convertCurrency() . 99 FIND {SearchQuery} . 100 FORMAT() . 104 IN SearchGroup . 104 LIMIT n . 105 OFFSET n . 106 ORDER BY Clause . 107 RETURNING FieldSpec . 107 toLabel(fields) . 110 Update an Article’s Keyword Tracking with SOSL . 111 Update an Article’s Viewstat with SOSL . 111 USING Listview= . 112 WHERE conditionExpression . 112 WITH DATA CATEGORY DataCategorySpec . 116 WITH DivisionFilter . 118 WITH HIGHLIGHT . 118 WITH METADATA . 120 WITH NETWORK NetworkIdSpec . 120 WITH PricebookId . 121 WITH SNIPPET . 121 WITH SPELL_CORRECTION . ..