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