• APEX初步 [6] —— SOSL查询


    Salesforce Object Search Language (SOSL)是Salesforce在记录中搜索文本的语言。可以用来在多个标准或自定义对象中搜索文本,类似Apache Lucene。

    可以在apex语句中直接嵌入SOSL语句,这种用法叫做Inline SOSL

    List<List<SObject>> searchList = [FIND 'SFDC' IN ALL FIELDS 
                                          RETURNING Account(Name), Contact(FirstName,LastName)];

    上面这句语句用来查询 任何字段中包含有‘SFDC’这个词的的客户和联系人。

    请注意在APEX中的搜索文本要用单引号‘SFDC’,在Query Editor中要用大括号{SFDC}

    SOQL ,SOSL之间的不同之处和相似之处

    • SOQL 用来从单个对象上获取记录
    • SOSL在多个对象上搜索文本字段

     下面是SOSL的标准格式:

    FIND 'SearchQuery' [IN SearchGroup] [RETURNING ObjectsAndFields]
    

     

    SearchQuery is the text to search for (a single word or a phrase). Search terms can be grouped with logical operators (AND, OR) and parentheses. Also, search terms can include wildcard characters (*, ?). The * wildcard matches zero or more characters at the middle or end of the search term. The ? wildcard matches only one character at the middle or end of the search term.

    Text searches are case-insensitive. For example, searching for Customercustomer, or CUSTOMER all return the same results.

    SearchGroup is optional. It is the scope of the fields to search. If not specified, the default search scope is all fields. SearchGroup can take one of the following values.

    • ALL FIELDS
    • NAME FIELDS
    • EMAIL FIELDS
    • PHONE FIELDS
    • SIDEBAR FIELDS

    ObjectsAndFields is optional. It is the information to return in the search result—a list of one or more sObjects and, within each sObject, list of one or more fields, with optional values to filter against. If not specified, the search results contain the IDs of all objects found.

    Search in all fields for:Search DescriptionMatched Records and Fields
    The Query This search returns all records whose fields contain both words: The and Query, in any location of the text. The order of words in the search term doesn’t matter. Account: The SFDC Query Man (Name field matched)
    Wingo OR Man This search uses the OR logical operator. It returns records with fields containing the Wingo word or records with fields containing the SFDC word. Contact: Carol Ruiz, Department: 'Wingo'

    Account: The SFDC Query Man (Name field matched)

    1212 This search returns all records whose fields contain the 1212 word. Phone fields that end with -1212 are matched because 1212 is considered a word when delimited by the dash. Account: The SFDC Query Man, Phone: '(415)555-1212'

    Contact: Carol Ruiz, Phone: '(415)555-1212'

    wing* This is a wildcard search. This search returns all records that have a field value starting with wing. Contact: Maria Ruiz, Department: 'Wingo'

    Account: The SFDC Query Man, Description: 'Expert in wing technologies.'

    List<List<sObject>> searchList = [FIND 'Wingo OR SFDC' IN ALL FIELDS 
                       RETURNING Account(Name),Contact(FirstName,LastName,Department)];
    Account[] searchAccounts = (Account[])searchList[0];
    Contact[] searchContacts = (Contact[])searchList[1];
    
    System.debug('Found the following accounts.');
    for (Account a : searchAccounts) {
        System.debug(a.Name);
    }
    
    System.debug('Found the following contacts.');
    for (Contact c : searchContacts) {
        System.debug(c.LastName + ', ' + c.FirstName);
    }
  • 相关阅读:
    061.Python前端Django组件用户认证组件
    060.Python组件-中间件
    059.Python前端Django组件cooki和session
    058.Python前端Django与Ajax
    057.Python前端Django模型ORM多表查询
    数字签名与数字证书的原理
    加密算法的分类与区别
    Linux操作php.ini文件
    Linux添加普通权限账号并授予root权限
    Linux 切换 shell
  • 原文地址:https://www.cnblogs.com/abovecloud/p/6506931.html
Copyright © 2020-2023  润新知