a!sfcSearch() Function

Allows searching a Salesforce instance using the Salesforce Object Search Language. For more information on SOSL, refer to Salesforce SOSL reference documentation.

Syntax

a!sfcSearch( scsExternalSystemKey, usePerUserCredentials, endpoint, query)

Common Parameters:

scsExternalSystemKey: (Text) The key from the Third Party Credentials admin console page that corresponds to the set of credentials that should be used to authenticate.

usePerUserCredentials: (Boolean) If true the credentials set in the Third-Party Credentials settings page by the current user running the expression will be used. If false the site-wide credential values will be used.

endpoint: (Text) The Salesforce endpoint URL to use for authentication. Possible values are "https://login.salesforce.com/services/Soap/u/27.0", which is used for production and development environments, and "https://test.salesforce.com/services/Soap/u/27.0", which is used for the Salesforce "sandbox" test environment. Update the 27.0 portion of the endpoint URL to match the version of the API that you are accessing. As a best practice, create a constant for this value.

Specific Parameters:

query: (Text) The SOSL query to send to Salesforce

Returns

The function returns the standard connector result dictionary described in the main Connectors page.

If successful, the function returns a dictionary representation of the Salesforce SearchResult within the result field. Refer to Salesforce documentation for details regarding the contents of SearchResult.

Examples

Search for Contacts and Leads with a Given Phone Number

Copy and paste the expression into the INTERFACE DEFINITION in EXPRESSION MODE, save it, then call the interface in a Tempo Report to test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
=load(
  local!phone,
  with(
    local!searchResult: if(
      not(isnull(local!phone)),
      a!sfcSearch(
        scsExternalSystemKey: cons!SALESFORCE_SCS_KEY,
        usePerUserCredentials: true(),
        endpoint: cons!SALESFORCE_ENDPOINT,
          query: concat(
          "FIND {",
          local!phone,
          "} IN Phone FIELDS RETURNING ",
          "Contact(Id, Phone, FirstName, LastName), ",
          "Lead(Id, Phone, FirstName, LastName) "
        )
      ),
      null
    ),
    local!contactsAndLeads: if(
      local!searchResult.success, 
      {
        contacts: toDataSubset(local!searchResult.result.Contact), 
        leads: toDataSubset(local!searchResult.result.Lead)
      },
      null
    ),
    {
        a!textField(
          label: "Phone Number",
          instructions: "Enter a phone number to search for contacts and leads",
          value: local!phone,
          saveInto: a!save(
            local!phone,
            stripwith(save!value, "+()- ")
          )
        ),
        if(
          isnull(local!searchResult),
          {},
          if(
            isnull(local!contactsAndLeads),
            a!textField(
              label: "An error occurred",
              readOnly:true,
              value: local!searchResult.error.message
            ),
            {
              a!gridField(
                totalCount: local!contactsAndLeads.contacts.totalCount,
                label:"Matching Contacts",
                columns:{
                  a!gridTextColumn(
                    label: "Last Name",
                    data: index(local!contactsAndLeads.contacts.data, "LastName", null)
                  ),
                  a!gridTextColumn(
                    label: "First Name",
                    data: index(local!contactsAndLeads.contacts.data, "FirstName", null)
                  )
                },
                value: a!pagingInfo(
                  startIndex: 1, 
                  batchSize: -1
                )
              ),
              a!gridField(
                totalCount: local!contactsAndLeads.leads.totalCount,
                label:"Matching Leads",
                columns:{
                  a!gridTextColumn(
                    label: "Last Name",
                    data: index(local!contactsAndLeads.leads.data, "LastName", null)
                  ),
                  a!gridTextColumn(
                    label: "First Name",
                    data: index(local!contactsAndLeads.leads.data, "FirstName", null)
                  )
                },
                value: a!pagingInfo(
                  startIndex: 1, 
                  batchSize: -1
                )
              )
            }
          )
        )
    }
  )
)
FEEDBACK