Chilkat Online Tools

unicodeC / Salesforce Platform APIs / Access Records

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;
    int locationColumn;
    int locationLine;
    const wchar_t *name;
    const wchar_t *v_type;
    int j;
    int count_j;
    const wchar_t *strVal;
    const wchar_t *returnType;
    const wchar_t *v_Type;
    const wchar_t *v_Url;
    const wchar_t *Id;
    const wchar_t *NamespacePrefix;
    const wchar_t *Name;
    int ApiVersion;
    const wchar_t *Status;
    BOOL IsValid;
    int BodyCrc;
    const wchar_t *Body;
    int LengthWithoutComments;
    const wchar_t *CreatedDate;
    const wchar_t *CreatedById;
    const wchar_t *LastModifiedDate;
    const wchar_t *LastModifiedById;
    const wchar_t *SystemModstamp;
    const wchar_t *ManageableState;
    const wchar_t *SymbolTableId;
    const wchar_t *Key;
    const wchar_t *SymbolTableName;
    const wchar_t *Namespace;
    const wchar_t *ParentClass;
    int Column;
    int Line;
    const wchar_t *TableDeclarationName;
    const wchar_t *TableDeclarationType;
    int MetadataApiVersion;
    const wchar_t *MetadataStatus;
    const wchar_t *Urls;
    const wchar_t *FullName;
    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}}/tooling/sobjects/:SOBJECT_API_NAME/:RECORD_ID",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)

    // {
    //   "attributes": {
    //     "type": "ApexClass",
    //     "url": "/services/data/v59.0/tooling/sobjects/ApexClass/01p4H00000A4kfqQAB"
    //   },
    //   "Id": "01p4H00000A4kfqQAB",
    //   "NamespacePrefix": "smon",
    //   "Name": "GenericEventPostMock",
    //   "ApiVersion": 59,
    //   "Status": "Active",
    //   "IsValid": false,
    //   "BodyCrc": -1,
    //   "Body": "/*\nThis file is generated and isn't the actual source code for this\nmanaged global class.\nThis read-only file shows the class's global constructors,\nmethods, variables, and properties.\nTo enable code to compile, all methods return null.\n*/\nglobal class GenericEventPostMock implements System.HttpCalloutMock {\n    global GenericEventPostMock(Integer statusCode) {\n\n    }\n    global System.HttpResponse respond(System.HttpRequest req) {\n        return null;\n    }\n}\n",
    //   "LengthWithoutComments": -1,
    //   "CreatedDate": "2023-11-20T08:03:40.000+0000",
    //   "CreatedById": "00558000000yFyDAAU",
    //   "LastModifiedDate": "2023-11-20T08:03:40.000+0000",
    //   "LastModifiedById": "00558000000yFyDAAU",
    //   "SystemModstamp": "2023-11-26T14:10:11.000+0000",
    //   "ManageableState": "installed",
    //   "SymbolTable": {
    //     "constructors": [
    //       {
    //         "annotations": [
    //         ],
    //         "location": {
    //           "column": 12,
    //           "line": 5
    //         },
    //         "modifiers": [
    //           "global"
    //         ],
    //         "name": "GenericEventPostMock",
    //         "parameters": [
    //           {
    //             "name": "statusCode",
    //             "type": "Integer"
    //           }
    //         ],
    //         "references": [
    //         ],
    //         "type": null
    //       }
    //     ],
    //     "externalReferences": [
    //     ],
    //     "id": "smon.GenericEventPostMock",
    //     "innerClasses": [
    //     ],
    //     "interfaces": [
    //       "System.HttpCalloutMock"
    //     ],
    //     "key": "smon.GenericEventPostMock",
    //     "methods": [
    //       {
    //         "annotations": [
    //         ],
    //         "location": {
    //           "column": 25,
    //           "line": 9
    //         },
    //         "modifiers": [
    //           "global"
    //         ],
    //         "name": "respond",
    //         "parameters": [
    //           {
    //             "name": "req",
    //             "type": "System.HttpRequest"
    //           }
    //         ],
    //         "references": [
    //         ],
    //         "returnType": "System.HttpResponse",
    //         "type": null
    //       }
    //     ],
    //     "name": "GenericEventPostMock",
    //     "namespace": "smon",
    //     "parentClass": "",
    //     "properties": [
    //     ],
    //     "tableDeclaration": {
    //       "annotations": [
    //         {
    //           "name": "IsTest"
    //         }
    //       ],
    //       "location": {
    //         "column": 14,
    //         "line": 2
    //       },
    //       "modifiers": [
    //         "testMethod",
    //         "global"
    //       ],
    //       "name": "GenericEventPostMock",
    //       "references": [
    //       ],
    //       "type": "smon.GenericEventPostMock"
    //     },
    //     "variables": [
    //     ]
    //   },
    //   "Metadata": {
    //     "apiVersion": 59,
    //     "packageVersions": [
    //     ],
    //     "status": "Active",
    //     "urls": null
    //   },
    //   "FullName": "smon__GenericEventPostMock"
    // }

    // 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.

    v_Type = CkJsonObjectW_stringOf(jResp,L"attributes.type");
    v_Url = CkJsonObjectW_stringOf(jResp,L"attributes.url");
    Id = CkJsonObjectW_stringOf(jResp,L"Id");
    NamespacePrefix = CkJsonObjectW_stringOf(jResp,L"NamespacePrefix");
    Name = CkJsonObjectW_stringOf(jResp,L"Name");
    ApiVersion = CkJsonObjectW_IntOf(jResp,L"ApiVersion");
    Status = CkJsonObjectW_stringOf(jResp,L"Status");
    IsValid = CkJsonObjectW_BoolOf(jResp,L"IsValid");
    BodyCrc = CkJsonObjectW_IntOf(jResp,L"BodyCrc");
    Body = CkJsonObjectW_stringOf(jResp,L"Body");
    LengthWithoutComments = CkJsonObjectW_IntOf(jResp,L"LengthWithoutComments");
    CreatedDate = CkJsonObjectW_stringOf(jResp,L"CreatedDate");
    CreatedById = CkJsonObjectW_stringOf(jResp,L"CreatedById");
    LastModifiedDate = CkJsonObjectW_stringOf(jResp,L"LastModifiedDate");
    LastModifiedById = CkJsonObjectW_stringOf(jResp,L"LastModifiedById");
    SystemModstamp = CkJsonObjectW_stringOf(jResp,L"SystemModstamp");
    ManageableState = CkJsonObjectW_stringOf(jResp,L"ManageableState");
    SymbolTableId = CkJsonObjectW_stringOf(jResp,L"SymbolTable.id");
    Key = CkJsonObjectW_stringOf(jResp,L"SymbolTable.key");
    SymbolTableName = CkJsonObjectW_stringOf(jResp,L"SymbolTable.name");
    Namespace = CkJsonObjectW_stringOf(jResp,L"SymbolTable.namespace");
    ParentClass = CkJsonObjectW_stringOf(jResp,L"SymbolTable.parentClass");
    Column = CkJsonObjectW_IntOf(jResp,L"SymbolTable.tableDeclaration.location.column");
    Line = CkJsonObjectW_IntOf(jResp,L"SymbolTable.tableDeclaration.location.line");
    TableDeclarationName = CkJsonObjectW_stringOf(jResp,L"SymbolTable.tableDeclaration.name");
    TableDeclarationType = CkJsonObjectW_stringOf(jResp,L"SymbolTable.tableDeclaration.type");
    MetadataApiVersion = CkJsonObjectW_IntOf(jResp,L"Metadata.apiVersion");
    MetadataStatus = CkJsonObjectW_stringOf(jResp,L"Metadata.status");
    Urls = CkJsonObjectW_stringOf(jResp,L"Metadata.urls");
    FullName = CkJsonObjectW_stringOf(jResp,L"FullName");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.constructors");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        locationColumn = CkJsonObjectW_IntOf(jResp,L"SymbolTable.constructors[i].location.column");
        locationLine = CkJsonObjectW_IntOf(jResp,L"SymbolTable.constructors[i].location.line");
        name = CkJsonObjectW_stringOf(jResp,L"SymbolTable.constructors[i].name");
        v_type = CkJsonObjectW_stringOf(jResp,L"SymbolTable.constructors[i].type");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.constructors[i].annotations");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.constructors[i].modifiers");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"SymbolTable.constructors[i].modifiers[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.constructors[i].parameters");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            name = CkJsonObjectW_stringOf(jResp,L"SymbolTable.constructors[i].parameters[j].name");
            v_type = CkJsonObjectW_stringOf(jResp,L"SymbolTable.constructors[i].parameters[j].type");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.constructors[i].references");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.externalReferences");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.innerClasses");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.interfaces");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"SymbolTable.interfaces[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.methods");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        locationColumn = CkJsonObjectW_IntOf(jResp,L"SymbolTable.methods[i].location.column");
        locationLine = CkJsonObjectW_IntOf(jResp,L"SymbolTable.methods[i].location.line");
        name = CkJsonObjectW_stringOf(jResp,L"SymbolTable.methods[i].name");
        returnType = CkJsonObjectW_stringOf(jResp,L"SymbolTable.methods[i].returnType");
        v_type = CkJsonObjectW_stringOf(jResp,L"SymbolTable.methods[i].type");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.methods[i].annotations");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.methods[i].modifiers");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"SymbolTable.methods[i].modifiers[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.methods[i].parameters");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            name = CkJsonObjectW_stringOf(jResp,L"SymbolTable.methods[i].parameters[j].name");
            v_type = CkJsonObjectW_stringOf(jResp,L"SymbolTable.methods[i].parameters[j].type");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.methods[i].references");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.properties");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.tableDeclaration.annotations");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        name = CkJsonObjectW_stringOf(jResp,L"SymbolTable.tableDeclaration.annotations[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.tableDeclaration.modifiers");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"SymbolTable.tableDeclaration.modifiers[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.tableDeclaration.references");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"SymbolTable.variables");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Metadata.packageVersions");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        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}}/tooling/sobjects/:SOBJECT_API_NAME/:RECORD_ID

Postman Collection Item JSON

{
  "name": "Access Records",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/tooling/sobjects/:SOBJECT_API_NAME/:RECORD_ID",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "tooling",
        "sobjects",
        ":SOBJECT_API_NAME",
        ":RECORD_ID"
      ],
      "variable": [
        {
          "key": "SOBJECT_API_NAME",
          "value": ""
        },
        {
          "key": "RECORD_ID",
          "value": ""
        }
      ]
    }
  },
  "response": [
    {
      "name": "Access Records",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/tooling/sobjects/:SOBJECT_API_NAME/:RECORD_ID",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "tooling",
            "sobjects",
            ":SOBJECT_API_NAME",
            ":RECORD_ID"
          ],
          "variable": [
            {
              "key": "SOBJECT_API_NAME",
              "value": "ApexClass"
            },
            {
              "key": "RECORD_ID",
              "value": "01p4H00000A4kfqQAB"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Mon, 11 Dec 2023 10:38:26 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=308/15000"
        },
        {
          "key": "Last-Modified",
          "value": "Sun, 26 Nov 2023 14:10:11 GMT"
        },
        {
          "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    \"attributes\": {\n        \"type\": \"ApexClass\",\n        \"url\": \"/services/data/v59.0/tooling/sobjects/ApexClass/01p4H00000A4kfqQAB\"\n    },\n    \"Id\": \"01p4H00000A4kfqQAB\",\n    \"NamespacePrefix\": \"smon\",\n    \"Name\": \"GenericEventPostMock\",\n    \"ApiVersion\": 59,\n    \"Status\": \"Active\",\n    \"IsValid\": false,\n    \"BodyCrc\": -1,\n    \"Body\": \"/*\\nThis file is generated and isn't the actual source code for this\\nmanaged global class.\\nThis read-only file shows the class's global constructors,\\nmethods, variables, and properties.\\nTo enable code to compile, all methods return null.\\n*/\\nglobal class GenericEventPostMock implements System.HttpCalloutMock {\\n    global GenericEventPostMock(Integer statusCode) {\\n\\n    }\\n    global System.HttpResponse respond(System.HttpRequest req) {\\n        return null;\\n    }\\n}\\n\",\n    \"LengthWithoutComments\": -1,\n    \"CreatedDate\": \"2023-11-20T08:03:40.000+0000\",\n    \"CreatedById\": \"00558000000yFyDAAU\",\n    \"LastModifiedDate\": \"2023-11-20T08:03:40.000+0000\",\n    \"LastModifiedById\": \"00558000000yFyDAAU\",\n    \"SystemModstamp\": \"2023-11-26T14:10:11.000+0000\",\n    \"ManageableState\": \"installed\",\n    \"SymbolTable\": {\n        \"constructors\": [\n            {\n                \"annotations\": [],\n                \"location\": {\n                    \"column\": 12,\n                    \"line\": 5\n                },\n                \"modifiers\": [\n                    \"global\"\n                ],\n                \"name\": \"GenericEventPostMock\",\n                \"parameters\": [\n                    {\n                        \"name\": \"statusCode\",\n                        \"type\": \"Integer\"\n                    }\n                ],\n                \"references\": [],\n                \"type\": null\n            }\n        ],\n        \"externalReferences\": [],\n        \"id\": \"smon.GenericEventPostMock\",\n        \"innerClasses\": [],\n        \"interfaces\": [\n            \"System.HttpCalloutMock\"\n        ],\n        \"key\": \"smon.GenericEventPostMock\",\n        \"methods\": [\n            {\n                \"annotations\": [],\n                \"location\": {\n                    \"column\": 25,\n                    \"line\": 9\n                },\n                \"modifiers\": [\n                    \"global\"\n                ],\n                \"name\": \"respond\",\n                \"parameters\": [\n                    {\n                        \"name\": \"req\",\n                        \"type\": \"System.HttpRequest\"\n                    }\n                ],\n                \"references\": [],\n                \"returnType\": \"System.HttpResponse\",\n                \"type\": null\n            }\n        ],\n        \"name\": \"GenericEventPostMock\",\n        \"namespace\": \"smon\",\n        \"parentClass\": \"\",\n        \"properties\": [],\n        \"tableDeclaration\": {\n            \"annotations\": [\n                {\n                    \"name\": \"IsTest\"\n                }\n            ],\n            \"location\": {\n                \"column\": 14,\n                \"line\": 2\n            },\n            \"modifiers\": [\n                \"testMethod\",\n                \"global\"\n            ],\n            \"name\": \"GenericEventPostMock\",\n            \"references\": [],\n            \"type\": \"smon.GenericEventPostMock\"\n        },\n        \"variables\": []\n    },\n    \"Metadata\": {\n        \"apiVersion\": 59,\n        \"packageVersions\": [],\n        \"status\": \"Active\",\n        \"urls\": null\n    },\n    \"FullName\": \"smon__GenericEventPostMock\"\n}"
    }
  ]
}