Chilkat Online Tools

unicodeC / Salesforce Platform APIs / Get Lookup Field Suggestions

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *apiName;
    const wchar_t *eTag;
    const wchar_t *DisplayValue;
    const wchar_t *Value;
    const wchar_t *NameDisplayValue;
    const wchar_t *NameValue;
    const wchar_t *SiteDisplayValue;
    const wchar_t *SiteValue;
    const wchar_t *id;
    const wchar_t *lastModifiedById;
    const wchar_t *lastModifiedDate;
    const wchar_t *recordTypeId;
    const wchar_t *recordTypeInfo;
    const wchar_t *systemModstamp;
    int weakEtag;
    int Count;
    const wchar_t *CurrentPageToken;
    const wchar_t *CurrentPageUrl;
    const wchar_t *NextPageToken;
    const wchar_t *NextPageUrl;
    const wchar_t *PreviousPageToken;
    const wchar_t *PreviousPageUrl;
    const wchar_t *FieldApiName;
    const wchar_t *ObjectApiName;
    const wchar_t *SecondaryField;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://domain.com/services/data/v{{version}}/ui-api/lookups/:SOBJECT_API_NAME/:FIELD_API_NAME",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "lookupResults": {
    //     "Account": {
    //       "count": 2,
    //       "currentPageToken": null,
    //       "currentPageUrl": "/services/data/v58.0/ui-api/lookups/Contact/AccountId/Account?searchType=Recent&page=1&pageSize=25",
    //       "nextPageToken": null,
    //       "nextPageUrl": null,
    //       "previousPageToken": null,
    //       "previousPageUrl": null,
    //       "records": [
    //         {
    //           "apiName": "Account",
    //           "childRelationships": {},
    //           "eTag": "610a250509b966f2eb376b3205824a8b",
    //           "fields": {
    //             "Id": {
    //               "displayValue": null,
    //               "value": "001B000000UnQ2yIAF"
    //             },
    //             "Name": {
    //               "displayValue": null,
    //               "value": "Dickenson plc"
    //             },
    //             "Site": {
    //               "displayValue": null,
    //               "value": null
    //             }
    //           },
    //           "id": "001B000000UnQ2yIAF",
    //           "lastModifiedById": "005B0000003TOI6IAO",
    //           "lastModifiedDate": "2017-08-18T14:46:22.000Z",
    //           "recordTypeId": "012000000000000AAA",
    //           "recordTypeInfo": null,
    //           "systemModstamp": "2017-08-18T14:46:22.000Z",
    //           "weakEtag": 1503067582000
    //         },
    //         {
    //           "apiName": "Account",
    //           "childRelationships": {},
    //           "eTag": "d0b7cec61a65e01f88b2596dea75cbd8",
    //           "fields": {
    //             "Id": {
    //               "displayValue": null,
    //               "value": "001B000000UnQ2wIAF"
    //             },
    //             "Name": {
    //               "displayValue": null,
    //               "value": "Burlington Textiles Corp of America"
    //             },
    //             "Site": {
    //               "displayValue": null,
    //               "value": null
    //             }
    //           },
    //           "id": "001B000000UnQ2wIAF",
    //           "lastModifiedById": "005B0000003TOI6IAO",
    //           "lastModifiedDate": "2017-08-18T14:46:22.000Z",
    //           "recordTypeId": "012000000000000AAA",
    //           "recordTypeInfo": null,
    //           "systemModstamp": "2017-08-18T14:46:22.000Z",
    //           "weakEtag": 1503067582000
    //         }
    //       ]
    //     }
    //   },
    //   "metadata": {
    //     "Account": {
    //       "fieldApiName": null,
    //       "objectApiName": null,
    //       "secondaryField": "Site",
    //       "targetInfo": {}
    //     }
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Count = CkJsonObjectW_IntOf(jResp,L"lookupResults.Account.count");
    CurrentPageToken = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.currentPageToken");
    CurrentPageUrl = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.currentPageUrl");
    NextPageToken = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.nextPageToken");
    NextPageUrl = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.nextPageUrl");
    PreviousPageToken = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.previousPageToken");
    PreviousPageUrl = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.previousPageUrl");
    FieldApiName = CkJsonObjectW_stringOf(jResp,L"metadata.Account.fieldApiName");
    ObjectApiName = CkJsonObjectW_stringOf(jResp,L"metadata.Account.objectApiName");
    SecondaryField = CkJsonObjectW_stringOf(jResp,L"metadata.Account.secondaryField");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"lookupResults.Account.records");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        apiName = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].apiName");
        eTag = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].eTag");
        DisplayValue = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].fields.Id.displayValue");
        Value = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].fields.Id.value");
        NameDisplayValue = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].fields.Name.displayValue");
        NameValue = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].fields.Name.value");
        SiteDisplayValue = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].fields.Site.displayValue");
        SiteValue = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].fields.Site.value");
        id = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].id");
        lastModifiedById = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].lastModifiedById");
        lastModifiedDate = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].lastModifiedDate");
        recordTypeId = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].recordTypeId");
        recordTypeInfo = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].recordTypeInfo");
        systemModstamp = CkJsonObjectW_stringOf(jResp,L"lookupResults.Account.records[i].systemModstamp");
        weakEtag = CkJsonObjectW_IntOf(jResp,L"lookupResults.Account.records[i].weakEtag");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/ui-api/lookups/:SOBJECT_API_NAME/:FIELD_API_NAME

Postman Collection Item JSON

{
  "name": "Get Lookup Field Suggestions",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": ""
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/lookups/:SOBJECT_API_NAME/:FIELD_API_NAME",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "ui-api",
        "lookups",
        ":SOBJECT_API_NAME",
        ":FIELD_API_NAME"
      ],
      "query": [
        {
          "key": "dependentFieldBindings",
          "value": "",
          "description": "The dependent field bindings for dependent lookups. These field bindings represent the lookup filter that restricts the valid values for the field.\nSpecify field bindings in a comma-separated list in the format dependentFieldBindings=<FIELD_API_NAME1>=<FIELD_VALUE1>,<FIELD_API_NAME2>=<FIELD_VALUE2>.\n\nTo know whether a field is a dependent lookup, check the Object Info response body for a non-null filteredLookupInfo property. Specify the name and a value for each field in the controllingFields property. Get the field values from the Record response body. Both responses are returned from the /ui-api/record-ui/<RECORD_IDS> resource.",
          "disabled": true
        },
        {
          "key": "page",
          "value": "",
          "description": "The page number. The default value is 1.",
          "disabled": true
        },
        {
          "key": "pageSize",
          "value": "",
          "description": "The number of items per page. The default value is 25.\n",
          "disabled": true
        },
        {
          "key": "q",
          "value": "",
          "description": "The term the user is searching for.\nWhen 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.\n\nWhen searchType=TypeAhead, specify at least 3 characters. A wildcard at the end of the search term is implied. You can’t use a ?.",
          "disabled": true
        },
        {
          "key": "searchType",
          "value": "",
          "description": "The type of search to perform. One of these values:\nRecent—Return most recently used matches.\nSearch—Search for records with searchable fields that match the query term.\nTypeAhead—Search for records whose names start with the query term.\nThe default value is Recent.",
          "disabled": true
        }
      ],
      "variable": [
        {
          "key": "SOBJECT_API_NAME",
          "value": "",
          "description": "sObject API name"
        },
        {
          "key": "FIELD_API_NAME",
          "value": "",
          "description": "Field API name"
        }
      ]
    },
    "description": "When a user edits a lookup field, use this resource to search for and display suggestions. You can search for most recently used matches, for matching names, or for any match in a searchable field. You can also specify lookup filter bindings for dependent lookups."
  },
  "response": [
    {
      "name": "Get Lookup Field Suggestions",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": ""
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/lookups/:SOBJECT_API_NAME/:FIELD_API_NAME",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "ui-api",
            "lookups",
            ":SOBJECT_API_NAME",
            ":FIELD_API_NAME"
          ],
          "query": [
            {
              "key": "dependentFieldBindings",
              "value": "",
              "description": "The dependent field bindings for dependent lookups. These field bindings represent the lookup filter that restricts the valid values for the field.\nSpecify field bindings in a comma-separated list in the format dependentFieldBindings=<FIELD_API_NAME1>=<FIELD_VALUE1>,<FIELD_API_NAME2>=<FIELD_VALUE2>.\n\nTo know whether a field is a dependent lookup, check the Object Info response body for a non-null filteredLookupInfo property. Specify the name and a value for each field in the controllingFields property. Get the field values from the Record response body. Both responses are returned from the /ui-api/record-ui/<RECORD_IDS> resource.",
              "disabled": true
            },
            {
              "key": "page",
              "value": "",
              "description": "The page number. The default value is 1.",
              "disabled": true
            },
            {
              "key": "pageSize",
              "value": "",
              "description": "The number of items per page. The default value is 25.\n",
              "disabled": true
            },
            {
              "key": "q",
              "value": "",
              "description": "The term the user is searching for.\nWhen 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.\n\nWhen searchType=TypeAhead, specify at least 3 characters. A wildcard at the end of the search term is implied. You can’t use a ?.",
              "disabled": true
            },
            {
              "key": "searchType",
              "value": "",
              "description": "The type of search to perform. One of these values:\nRecent—Return most recently used matches.\nSearch—Search for records with searchable fields that match the query term.\nTypeAhead—Search for records whose names start with the query term.\nThe default value is Recent.",
              "disabled": true
            }
          ],
          "variable": [
            {
              "key": "SOBJECT_API_NAME",
              "value": "Contact",
              "description": "sObject API name"
            },
            {
              "key": "FIELD_API_NAME",
              "value": "AccountId",
              "description": "Field API name"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 27 Sep 2023 16:07:13 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"lookupResults\": {\n        \"Account\": {\n            \"count\": 2,\n            \"currentPageToken\": null,\n            \"currentPageUrl\": \"/services/data/v58.0/ui-api/lookups/Contact/AccountId/Account?searchType=Recent&page=1&pageSize=25\",\n            \"nextPageToken\": null,\n            \"nextPageUrl\": null,\n            \"previousPageToken\": null,\n            \"previousPageUrl\": null,\n            \"records\": [\n                {\n                    \"apiName\": \"Account\",\n                    \"childRelationships\": {},\n                    \"eTag\": \"610a250509b966f2eb376b3205824a8b\",\n                    \"fields\": {\n                        \"Id\": {\n                            \"displayValue\": null,\n                            \"value\": \"001B000000UnQ2yIAF\"\n                        },\n                        \"Name\": {\n                            \"displayValue\": null,\n                            \"value\": \"Dickenson plc\"\n                        },\n                        \"Site\": {\n                            \"displayValue\": null,\n                            \"value\": null\n                        }\n                    },\n                    \"id\": \"001B000000UnQ2yIAF\",\n                    \"lastModifiedById\": \"005B0000003TOI6IAO\",\n                    \"lastModifiedDate\": \"2017-08-18T14:46:22.000Z\",\n                    \"recordTypeId\": \"012000000000000AAA\",\n                    \"recordTypeInfo\": null,\n                    \"systemModstamp\": \"2017-08-18T14:46:22.000Z\",\n                    \"weakEtag\": 1503067582000\n                },\n                {\n                    \"apiName\": \"Account\",\n                    \"childRelationships\": {},\n                    \"eTag\": \"d0b7cec61a65e01f88b2596dea75cbd8\",\n                    \"fields\": {\n                        \"Id\": {\n                            \"displayValue\": null,\n                            \"value\": \"001B000000UnQ2wIAF\"\n                        },\n                        \"Name\": {\n                            \"displayValue\": null,\n                            \"value\": \"Burlington Textiles Corp of America\"\n                        },\n                        \"Site\": {\n                            \"displayValue\": null,\n                            \"value\": null\n                        }\n                    },\n                    \"id\": \"001B000000UnQ2wIAF\",\n                    \"lastModifiedById\": \"005B0000003TOI6IAO\",\n                    \"lastModifiedDate\": \"2017-08-18T14:46:22.000Z\",\n                    \"recordTypeId\": \"012000000000000AAA\",\n                    \"recordTypeInfo\": null,\n                    \"systemModstamp\": \"2017-08-18T14:46:22.000Z\",\n                    \"weakEtag\": 1503067582000\n                }\n            ]\n        }\n    },\n    \"metadata\": {\n        \"Account\": {\n            \"fieldApiName\": null,\n            \"objectApiName\": null,\n            \"secondaryField\": \"Site\",\n            \"targetInfo\": {}\n        }\n    }\n}"
    }
  ]
}