Search for a String
Use the Search resource to execute a SOSL search or use
the Parameterized Search resource to execute a simple RESTful search without
SOSL.
Example SOSL Search Using the GET Method
The following example executes a SOSL search for Acme. The search string in this example must be URL-encoded.
- Example usage
-
curl https://MyDomainName.my.salesforce.com/services/data/v63.0/search/?q=FIND+%7BAcme%7D -H "Authorization: Bearer token"
- Example request body
- None required
- Example response body
-
{ "searchRecords" : [ { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001D000000IqhSLIAZ" }, "Id" : "001D000000IqhSLIAZ", }, { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001D000000IomazIAB" }, "Id" : "001D000000IomazIAB", } ] }
Example Parameterized Search Using the GET Method
The following example
executes a parameterized search for Acme. The
search string in this example must be URL-encoded.
- Example usages
- Global search for all results containing Acme
-
curl https://MyDomainName.my.salesforce.com/services/data/v63.0/parameterizedSearch/?q=Acme -H "Authorization: Bearer token"
- Account search for results containing Acme, returning the id and name fields
-
curl https://MyDomainName.my.salesforce.com/services/data/v63.0/parameterizedSearch/?q=Acme&sobject=Account&Account.fields=id,name&Account.limit=10 -H "Authorization: Bearer token"
- Example request body
- None required
- Example response body
-
{ "searchRecords" : [ { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001D000000IqhSLIAZ" }, "Id" : "001D000000IqhSLIAZ" }, { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001D000000IomazIAB" }, "Id" : "001D000000IomazIAB" } ] }
- Example response body with metadata parameter
-
{ "searchRecords" : [ { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001D000000IqhSLIAZ" }, "Id" : "001D000000IqhSLIAZ", }, { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001D000000IomazIAB" }, "Id" : "001D000000IomazIAB", } ], "metadata" : { "entityetadata" : [ { "entityName" : "Account", "fieldMetadata" : [ { "name" : "Name", "label" : "Account Name" } ] } ] } }
Example Parameterized Search Using the POST Method
Execute a
parameterized search using the POST method to access all search features available.
- Example usage
-
curl https://MyDomainName.my.salesforce.com/services/data/v63.0/parameterizedSearch "Authorization: Bearer token" -H "Content-Type: application/json” -d "@search.json”
- Example request body
- None required
- Example JSON file
-
{ "q":"Smith", "fields" : ["id", "firstName", "lastName"], "sobjects":[{"fields":["id", "NumberOfEmployees"], "name": "Account", "limit":20}, {"name": "Contact"}], "in":"ALL", "overallLimit":100, "defaultLimit":10 }
- Example response body
-
{ "searchRecords" : [ { "attributes" : { "type" : "Contact", "url" : "/services/data/v63.0/sobjects/Contact/003xx000004TraiAAC" }, "Id" : "003xx000004TraiAAC", "FirstName" : "Smith", "LastName" : "Johnson" }, { "attributes" : { "type" : "Account", "url" : "/services/data/v63.0/sobjects/Account/001xx000003DHXnAAO" }, "Id" : "001xx000003DHXnAAO", "NumberOfEmployees" : 100 } ] }