search()

Executes a text search in your organization’s data.

Use search() to search for records based on a search string. The search call supports searching custom objects. For an extensive discussion about the syntax and rules used for text searches, see the Salesforce SOQL and SOSL Reference Guide.

Certain objects cannot be searched via the API, such as Attachment objects. To search an object via the search() call, the object must be configured as searchable (isSearchable is true). To determine whether an object can be searched, your client application can invoke the describeSObjects() call on the object and inspect its searchable property.

This sample makes the search() call by passing it a SOSL query, which returns contacts, leads, and accounts whose phone fields contain a specified value. Next, it gets the sObject records from the results and stores the records in arrays depending on the record type. Finally, it writes the fields of the returned contacts, leads, and accounts to the console.

This sample makes the search() call by passing it a SOSL query, which returns contacts, leads, and accounts whose phone fields contain a specified value. Next, it gets the sObject records from the results and stores the records in arrays depending on the record type. Finally, it writes the fields of the returned contacts, leads, and accounts to the console.

NameTypeDescription
searchstringSearch string that specifies the text expression to search for, the scope of fields to search, the list of objects and fields to retrieve, and the maximum number of records to return. For more information, see the Salesforce SOQL and SOSL Reference Guide.

SearchResult

InvalidFieldFault

InvalidSObjectFault

MalformedSearchFault

UnexpectedErrorFault

See Also