Get Lookup Field Suggestions With POST
- Resource
-
/ui-api/lookups/{objectApiName}/{fieldApiName}
-
- objectApiName—The API name of a source object.
- fieldApiName—The API name of a lookup field on the source object.
- Available Version
- 60.0
- HTTP Method
- POST
- Example: Get Most Recently Used Records
- A lookup relationship field links a source object to a target object. To edit a lookup field, users click on a lookup field to search for and select a value from a popup list. The target object provides the values in the list.
- For example, the Opportunity object has an AccountId lookup
field. When a user edits an Opportunity record, the user selects an Account to associate
with the Opportunity. To build a UI that suggests the most recently used Account records
to the user, use this resource. The default value of the searchType parameter is Recent, so the
request doesn’t specify
it.
POST /ui-api/lookups/Opportunity/AccountId
- Example: Search for Suggestions using request parameters
- To search all searchable fields for suggestions, set searchType=Search. This example searches for strings that start with the
characters ca (a wildcard is implied).
POST /ui-api/lookups/Opportunity/AccountId?searchType=Search&q=ca
- Example: Search Record Names for Suggestions using request parameters
- To search record name fields for suggestions, set searchType=TypeAhead. This example searches record names for strings that
start with the characters ta (a wildcard is
implied).
POST /ui-api/lookups/Opportunity/AccountId?searchType=TypeAhead&q=ta
- Request Parameters for POST
-
Parameter Name Type Description Required or Optional Available Version page Integer The page number. The default value is 1. Optional 60.0 pageSize Integer The number of items per page. The default value is 25. Optional 60.0 q String The term the user is searching for. When searchType=Search, specify at least 2 characters. A wildcard at the end of the search term is implied. For example, q=ca returns Cat and Cats.
When searchType=TypeAhead, specify at least 3 characters. A wildcard at the end of the search term is implied. You can’t use a ?.
Required if searchType is TypeAhead. 60.0 searchType String The type of search to perform. One of these values: - Recent—Return most recently used matches.
- Search—Search for records with searchable fields that match the query term.
- TypeAhead—Search for records whose names start with the query term.
The default value is Recent.
Optional 60.0 targetApiName String[] The API name of the object that you want results for. The name must correspond to one of the target objects of the lookup field. If not provided, by default, results for all target objects of the lookup field are returned. If targetApiName isn’t specified, then the field configuration is used. If the field is polymorphic, several queries are considered and you receive results for every target that can lead to performance issues. Optional 60.0 - Request Body for POST
- Example: Search Dependent Lookups for Suggestions using the request body
- Some lookup fields have lookup filters that restrict their valid values by referencing fields on the source object. These fields are called dependent lookups. For example, you can filter the Case Contact field to show only contacts that are associated with the account selected in the Case Account Name field.
- In the Salesforce UI, this lookup filter is Contact Name: Account Name ID EQUALS Case: Account Name ID. In the User Interface API, lookup filter information appears in the filteredLookupInfo property of the Object Info response body, which is returned from several resources, including /ui-api/record-ui/{recordIds}. If the filteredLookupInfo property is non-null, the field it describes is a dependent lookup.
- In this example, the Case object’s ContactId field has a filteredLookupInfo property containing a controllingFields property. The controlling field is AccountId. To restrict the lookup search, you must pass
all controlling fields and their values to the lookups resource in the sourceRecord request body
property.
"objectInfos" : { ... "Case" : { "apiName" : "Case", ... "fields" : { ... "ContactId" : { "apiName" : "ContactId", ...properties removed for space... "filteredLookupInfo" : { "controllingFields" : [ "AccountId" ], "dependent" : true, "optionalFilter" : false }, ... "sortable" : true, "unique" : false, "updateable" : true }, ...
- To get the value for AccountId, look in the Record response body, which
is returned from several resources, including /ui-api/record-ui/{recordIds}. For example, to
retrieve the value of the AccountId field present on the Case
500R0000000bKpBIAU:
GET /ui-api/records/500R0000000bKpBIAU?fields=Case.AccountId
{ "apiName": "Case", "id": "500Z7000000bhdFIAQ", "fields": { "AccountId": { "displayValue": null, "value": "001R0000003IG0MIAW" } }, ...Some properties removed for space... }
- To filter the suggestions for a dependent lookup, specify the names and values of the controlling fields in the sourceRecord request body property. (This example has one controlling field).
- Request body:
-
POST /ui-api/lookups/case/ContactId { "sourceRecord": { "fields": { "Id": "500Z7000000bhdFIAQ", "AccountId": "001R0000003IG0MIAW" } }, "orderBy": [ { "fieldApiName": "Name", "isAscending":true } ] }
- Properties
-
Name Type Description Required or Optional Available Version orderBy List Order By Input[] Information describing how to order the results. Optional 63.0 sourceRecord Record Input The source record in which the lookup relationship field is being edited. The presence of the source record “Id” is required within the “fields” property. Accepted values are “null” when creating a new record and a valid record ID when updating an existing record.
Some lookup fields have lookup filters that restrict the values they can accept by referencing fields on the source object. These fields are called dependent lookup fields or controlling fields. You must pass all controlling fields and their values to the lookups resource within the “fields” property.
To know whether a field is a lookup controlling field, check the Object Info response body for a non-null filteredLookupInfo property. Get the field values from the Record response body. Both responses are returned from the /ui-api/record-ui/{recordIds} resource.
Properties “allowSaveOnDuplicate” and “apiName” are not used.Required 60.0
- Response Body
- Lookup Values