Get Lookup Values Examples

AVAILABLE API VERSION
API v68.0 and later

Get Most Recently Used Records for a Lookup Field 

This example gets the most recently used account record lookup values for the opportunity object.

Get Recent Account Lookups
1{
2  uiapi {
3    lookupValues(
4      objectApiName: "Opportunity"
5      fieldApiName: "AccountId"
6      searchType: RECENT
7    ) {
8      targetApiName
9      records {
10        edges {
11          node {
12            Record {
13              Id
14              DisplayValue
15            }
16          }
17        }
18        pageInfo {
19          hasNextPage
20          endCursor
21        }
22      }
23    }
24  }
25}

The previous query returns this response.

Response for Recent Account Lookups
1{
2  "data": {
3    "uiapi": {
4      "lookupValues": [
5        {
6          "targetApiName": "Account",
7          "records": {
8            "edges": [
9              {
10                "node": {
11                  "Record": {
12                    "Id": "001LT00000DzUzQYAV",
13                    "DisplayValue": "fong",
14                    "ApiName": "Account"
15                  }
16                }
17              },
18              {
19                "node": {
20                  "Record": {
21                    "Id": "001LT00000DzUzOYAV",
22                    "DisplayValue": "Acme12",
23                    "ApiName": "Account"
24                  }
25                }
26              }
27            ],
28            "pageInfo": {
29              "hasNextPage": false,
30              "endCursor": "djE6MTE="
31            }
32          }
33        }
34      ]
35    }
36  },
37  "errors": [],
38  "extensions": {}
39}

Search with Object-Specific Fields and Metadata 

This example searches for accounts on the opportunity object.

Search Fields and Metadata
1{
2  uiapi {
3    lookupValues(
4      objectApiName: "Opportunity"
5      fieldApiName:  "AccountId"
6      searchType:    SEARCH
7      q:             "acme"
8    ) {
9      targetApiName
10      secondaryField
11      suggestionsInfo { displayFields matchingFields }
12      records(
13        first: 10
14        orderBy: { AccountSearch: { Name: { order: ASC } } }
15      ) {
16        edges {
17          node {
18            SecondaryFieldValue
19            Record {
20              Id
21              ApiName
22              DisplayValue
23              ... on AccountSearch {
24                Name        { value displayValue }
25                Industry    { value displayValue }
26                BillingCity { value displayValue }
27              }
28            }
29          }
30        }
31        pageInfo { hasNextPage endCursor }
32      }
33    }
34  }
35}

The previous query returns this response.

Response for Fields and Metadata Search
1{
2  "data": {
3    "uiapi": {
4      "lookupValues": [
5        {
6          "targetApiName": "Account",
7          "secondaryField": "Site",
8          "suggestionsInfo": {
9            "displayFields": [
10              "Name",
11              "Site"
12            ],
13            "matchingFields": [
14              "Name"
15            ]
16          },
17          "records": {
18            "edges": [
19              {
20                "node": {
21                  "SecondaryFieldValue": null,
22                  "Record": {
23                    "Id": "001LT00000DzV0RYAV",
24                    "ApiName": "Account",
25                    "DisplayValue": "acme",
26                    "Name": {
27                      "value": "acme",
28                      "displayValue": "acme"
29                    },
30                    "Industry": {
31                      "value": null,
32                      "displayValue": null
33                    },
34                    "BillingCity": {
35                      "value": null,
36                      "displayValue": null
37                    }
38                  }
39                }
40              },
41              {
42                "node": {
43                  "SecondaryFieldValue": null,
44                  "Record": {
45                    "Id": "001LT00000DzUzOYAV",
46                    "ApiName": "Account",
47                    "DisplayValue": "Acme12",
48                    "Name": {
49                      "value": "Acme12",
50                      "displayValue": "Acme12"
51                    },
52                    "Industry": {
53                      "value": "Manufacturing",
54                      "displayValue": "Manufacturing"
55                    },
56                    "BillingCity": {
57                      "value": "New York",
58                      "displayValue": "New York"
59                    }
60                  }
61                }
62              }
63            ],
64            "pageInfo": {
65              "hasNextPage": false,
66              "endCursor": "djE6Mg=="
67            }
68          }
69        }
70      ]
71    }
72  },
73  "errors": [],
74  "extensions": {}
75}

Get Lookup Values for a Polymorphic Field 

This example gets lookup values for the polymorphic contact ID field on cases.

Polymorphic Lookup
1{
2  uiapi {
3    lookupValues(
4      objectApiName: "Case"
5      fieldApiName:  "ContactId"
6      searchType:    SEARCH
7      q:             "john"
8    ) {
9      targetApiName
10      records {
11        edges {
12          node {
13            SecondaryFieldValue
14            Record {
15              Id
16              DisplayValue
17              ... on UserSearch  { Name { value } Email { value } }
18              ... on GroupSearch { Name { value } }
19            }
20          }
21        }
22      }
23    }
24  }
25}

The previous query returns this response.

Response for Polymorphic Lookup
1{
2  "data": {
3    "uiapi": {
4      "lookupValues": [
5        {
6          "targetApiName": "Contact",
7          "records": {
8            "edges": [
9              {
10                "node": {
11                  "SecondaryFieldValue": null,
12                  "Record": {
13                    "Id": "003LT00000D26oDYAR",
14                    "DisplayValue": "John Amos"
15                  }
16                }
17              },
18              {
19                "node": {
20                  "SecondaryFieldValue": null,
21                  "Record": {
22                    "Id": "003LT000001CFqlYAG",
23                    "DisplayValue": "Jon Amos"
24                  }
25                }
26              }
27            ]
28          }
29        }
30      ]
31    }
32  },
33  "errors": [],
34  "extensions": {}
35}

See Also 

Get Lookup Values