Chilkat Online Tools

PureBasic / Salesforce Platform APIs / Access Records

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://domain.com/services/data/v{{version}}/tooling/sobjects/:SOBJECT_API_NAME/:RECORD_ID",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; 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

    locationColumn.i
    locationLine.i
    name.s
    v_type.s
    j.i
    count_j.i
    strVal.s
    returnType.s

    v_Type.s = CkJsonObject::ckStringOf(jResp,"attributes.type")
    v_Url.s = CkJsonObject::ckStringOf(jResp,"attributes.url")
    Id.s = CkJsonObject::ckStringOf(jResp,"Id")
    NamespacePrefix.s = CkJsonObject::ckStringOf(jResp,"NamespacePrefix")
    Name.s = CkJsonObject::ckStringOf(jResp,"Name")
    ApiVersion.i = CkJsonObject::ckIntOf(jResp,"ApiVersion")
    Status.s = CkJsonObject::ckStringOf(jResp,"Status")
    IsValid.i = CkJsonObject::ckBoolOf(jResp,"IsValid")
    BodyCrc.i = CkJsonObject::ckIntOf(jResp,"BodyCrc")
    Body.s = CkJsonObject::ckStringOf(jResp,"Body")
    LengthWithoutComments.i = CkJsonObject::ckIntOf(jResp,"LengthWithoutComments")
    CreatedDate.s = CkJsonObject::ckStringOf(jResp,"CreatedDate")
    CreatedById.s = CkJsonObject::ckStringOf(jResp,"CreatedById")
    LastModifiedDate.s = CkJsonObject::ckStringOf(jResp,"LastModifiedDate")
    LastModifiedById.s = CkJsonObject::ckStringOf(jResp,"LastModifiedById")
    SystemModstamp.s = CkJsonObject::ckStringOf(jResp,"SystemModstamp")
    ManageableState.s = CkJsonObject::ckStringOf(jResp,"ManageableState")
    SymbolTableId.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.id")
    Key.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.key")
    SymbolTableName.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.name")
    Namespace.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.namespace")
    ParentClass.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.parentClass")
    Column.i = CkJsonObject::ckIntOf(jResp,"SymbolTable.tableDeclaration.location.column")
    Line.i = CkJsonObject::ckIntOf(jResp,"SymbolTable.tableDeclaration.location.line")
    TableDeclarationName.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.tableDeclaration.name")
    TableDeclarationType.s = CkJsonObject::ckStringOf(jResp,"SymbolTable.tableDeclaration.type")
    MetadataApiVersion.i = CkJsonObject::ckIntOf(jResp,"Metadata.apiVersion")
    MetadataStatus.s = CkJsonObject::ckStringOf(jResp,"Metadata.status")
    Urls.s = CkJsonObject::ckStringOf(jResp,"Metadata.urls")
    FullName.s = CkJsonObject::ckStringOf(jResp,"FullName")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.constructors")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        locationColumn = CkJsonObject::ckIntOf(jResp,"SymbolTable.constructors[i].location.column")
        locationLine = CkJsonObject::ckIntOf(jResp,"SymbolTable.constructors[i].location.line")
        name = CkJsonObject::ckStringOf(jResp,"SymbolTable.constructors[i].name")
        v_type = CkJsonObject::ckStringOf(jResp,"SymbolTable.constructors[i].type")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.constructors[i].annotations")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.constructors[i].modifiers")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"SymbolTable.constructors[i].modifiers[j]")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.constructors[i].parameters")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            name = CkJsonObject::ckStringOf(jResp,"SymbolTable.constructors[i].parameters[j].name")
            v_type = CkJsonObject::ckStringOf(jResp,"SymbolTable.constructors[i].parameters[j].type")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.constructors[i].references")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.externalReferences")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.innerClasses")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.interfaces")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"SymbolTable.interfaces[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.methods")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        locationColumn = CkJsonObject::ckIntOf(jResp,"SymbolTable.methods[i].location.column")
        locationLine = CkJsonObject::ckIntOf(jResp,"SymbolTable.methods[i].location.line")
        name = CkJsonObject::ckStringOf(jResp,"SymbolTable.methods[i].name")
        returnType = CkJsonObject::ckStringOf(jResp,"SymbolTable.methods[i].returnType")
        v_type = CkJsonObject::ckStringOf(jResp,"SymbolTable.methods[i].type")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.methods[i].annotations")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.methods[i].modifiers")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"SymbolTable.methods[i].modifiers[j]")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.methods[i].parameters")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            name = CkJsonObject::ckStringOf(jResp,"SymbolTable.methods[i].parameters[j].name")
            v_type = CkJsonObject::ckStringOf(jResp,"SymbolTable.methods[i].parameters[j].type")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.methods[i].references")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.properties")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.tableDeclaration.annotations")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        name = CkJsonObject::ckStringOf(jResp,"SymbolTable.tableDeclaration.annotations[i].name")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.tableDeclaration.modifiers")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"SymbolTable.tableDeclaration.modifiers[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.tableDeclaration.references")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"SymbolTable.variables")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"Metadata.packageVersions")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

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}"
    }
  ]
}