---
schema_version: "1"
id: 5bf91ecb813581d4807410fd939ed1bd27de76d4d1b8a94b864b98dcc5697ed4
title: Get Lookup Values Examples
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/graphql-api/graphql/guides/query/query-lookup-values-examples.md
canonical_url: https://developer.salesforce.com/docs/platform/graphql/guide/query-lookup-values-examples.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e4c291ada3051b6f6812ab4aa6231732b66127e5b506e5c20468e7f073bfe076
products:
  - GraphQL API
---
# 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.

```
{
  uiapi {
    lookupValues(
      objectApiName: "Opportunity"
      fieldApiName: "AccountId"
      searchType: RECENT
    ) {
      targetApiName
      records {
        edges {
          node {
            Record {
              Id
              DisplayValue
            }
          }
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  }
}
```

The previous query returns this response.

```
{
  "data": {
    "uiapi": {
      "lookupValues": [
        {
          "targetApiName": "Account",
          "records": {
            "edges": [
              {
                "node": {
                  "Record": {
                    "Id": "001LT00000DzUzQYAV",
                    "DisplayValue": "fong",
                    "ApiName": "Account"
                  }
                }
              },
              {
                "node": {
                  "Record": {
                    "Id": "001LT00000DzUzOYAV",
                    "DisplayValue": "Acme12",
                    "ApiName": "Account"
                  }
                }
              }
            ],
            "pageInfo": {
              "hasNextPage": false,
              "endCursor": "djE6MTE="
            }
          }
        }
      ]
    }
  },
  "errors": [],
  "extensions": {}
}
```

## Search with Object-Specific Fields and Metadata

This example searches for accounts on the opportunity object.

```
{
  uiapi {
    lookupValues(
      objectApiName: "Opportunity"
      fieldApiName:  "AccountId"
      searchType:    SEARCH
      q:             "acme"
    ) {
      targetApiName
      secondaryField
      suggestionsInfo { displayFields matchingFields }
      records(
        first: 10
        orderBy: { AccountSearch: { Name: { order: ASC } } }
      ) {
        edges {
          node {
            SecondaryFieldValue
            Record {
              Id
              ApiName
              DisplayValue
              ... on AccountSearch {
                Name        { value displayValue }
                Industry    { value displayValue }
                BillingCity { value displayValue }
              }
            }
          }
        }
        pageInfo { hasNextPage endCursor }
      }
    }
  }
}
```

The previous query returns this response.

```
{
  "data": {
    "uiapi": {
      "lookupValues": [
        {
          "targetApiName": "Account",
          "secondaryField": "Site",
          "suggestionsInfo": {
            "displayFields": [
              "Name",
              "Site"
            ],
            "matchingFields": [
              "Name"
            ]
          },
          "records": {
            "edges": [
              {
                "node": {
                  "SecondaryFieldValue": null,
                  "Record": {
                    "Id": "001LT00000DzV0RYAV",
                    "ApiName": "Account",
                    "DisplayValue": "acme",
                    "Name": {
                      "value": "acme",
                      "displayValue": "acme"
                    },
                    "Industry": {
                      "value": null,
                      "displayValue": null
                    },
                    "BillingCity": {
                      "value": null,
                      "displayValue": null
                    }
                  }
                }
              },
              {
                "node": {
                  "SecondaryFieldValue": null,
                  "Record": {
                    "Id": "001LT00000DzUzOYAV",
                    "ApiName": "Account",
                    "DisplayValue": "Acme12",
                    "Name": {
                      "value": "Acme12",
                      "displayValue": "Acme12"
                    },
                    "Industry": {
                      "value": "Manufacturing",
                      "displayValue": "Manufacturing"
                    },
                    "BillingCity": {
                      "value": "New York",
                      "displayValue": "New York"
                    }
                  }
                }
              }
            ],
            "pageInfo": {
              "hasNextPage": false,
              "endCursor": "djE6Mg=="
            }
          }
        }
      ]
    }
  },
  "errors": [],
  "extensions": {}
}
```

## Get Lookup Values for a Polymorphic Field

This example gets lookup values for the polymorphic contact ID field on cases.

```
{
  uiapi {
    lookupValues(
      objectApiName: "Case"
      fieldApiName:  "ContactId"
      searchType:    SEARCH
      q:             "john"
    ) {
      targetApiName
      records {
        edges {
          node {
            SecondaryFieldValue
            Record {
              Id
              DisplayValue
              ... on UserSearch  { Name { value } Email { value } }
              ... on GroupSearch { Name { value } }
            }
          }
        }
      }
    }
  }
}
```

The previous query returns this response.

```
{
  "data": {
    "uiapi": {
      "lookupValues": [
        {
          "targetApiName": "Contact",
          "records": {
            "edges": [
              {
                "node": {
                  "SecondaryFieldValue": null,
                  "Record": {
                    "Id": "003LT00000D26oDYAR",
                    "DisplayValue": "John Amos"
                  }
                }
              },
              {
                "node": {
                  "SecondaryFieldValue": null,
                  "Record": {
                    "Id": "003LT000001CFqlYAG",
                    "DisplayValue": "Jon Amos"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "errors": [],
  "extensions": {}
}
```

## See Also

[Get Lookup Values](https://developer.salesforce.com/docs/platform/graphql/guide/query-lookup-values.md)
