Chilkat Online Tools

PowerBuilder / Salesforce Platform APIs / Get Child Records

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_ApiName
string ls_ETag
string ls_DisplayValue
string ls_Value
string ls_IdDisplayValue
string ls_IdValue
string ls_NameDisplayValue
string ls_NameValue
string ls_Id
string ls_LastModifiedById
string ls_LastModifiedDate
string ls_RecordTypeId
string ls_RecordTypeInfo
string ls_SystemModstamp
integer li_WeakEtag
integer li_Count
string ls_CurrentPageToken
string ls_CurrentPageUrl
string ls_NextPageToken
string ls_NextPageUrl
string ls_PreviousPageToken
string ls_PreviousPageUrl
integer i
integer li_Count_i

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"

loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://domain.com/services/data/v{{version}}/ui-api/records/:RECORD_ID/child-relationships/:RELATIONSHIP_NAME",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

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

// {
//   "count": 1,
//   "currentPageToken": "1;5;001B000000UnQ2wIAF;Contacts;Contact.Id,Contact.Name;",
//   "currentPageUrl": "/services/data/v58.0/ui-api/records/001B000000UnQ2wIAF/child-relationships/Contacts?fields=Contact.Id%2CContact.Name&page=1&pageSize=5",
//   "nextPageToken": null,
//   "nextPageUrl": null,
//   "previousPageToken": null,
//   "previousPageUrl": null,
//   "records": [
//     {
//       "apiName": "Contact",
//       "childRelationships": {},
//       "eTag": "c3d33add9008aed557a1efa68173aa9b",
//       "fields": {
//         "AccountId": {
//           "displayValue": null,
//           "value": "001B000000UnQ2wIAF"
//         },
//         "Id": {
//           "displayValue": null,
//           "value": "003B00000097MToIAM"
//         },
//         "Name": {
//           "displayValue": null,
//           "value": "Jack Rogers"
//         }
//       },
//       "id": "003B00000097MToIAM",
//       "lastModifiedById": "005B0000003TOI6IAO",
//       "lastModifiedDate": "2017-08-18T14:46:22.000Z",
//       "recordTypeId": "012000000000000AAA",
//       "recordTypeInfo": null,
//       "systemModstamp": "2017-08-18T14:46:22.000Z",
//       "weakEtag": 1503067582000
//     }
//   ]
// }

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

li_Count = loo_JResp.IntOf("count")
ls_CurrentPageToken = loo_JResp.StringOf("currentPageToken")
ls_CurrentPageUrl = loo_JResp.StringOf("currentPageUrl")
ls_NextPageToken = loo_JResp.StringOf("nextPageToken")
ls_NextPageUrl = loo_JResp.StringOf("nextPageUrl")
ls_PreviousPageToken = loo_JResp.StringOf("previousPageToken")
ls_PreviousPageUrl = loo_JResp.StringOf("previousPageUrl")
i = 0
li_Count_i = loo_JResp.SizeOfArray("records")
do while i < li_Count_i
    loo_JResp.I = i
    ls_ApiName = loo_JResp.StringOf("records[i].apiName")
    ls_ETag = loo_JResp.StringOf("records[i].eTag")
    ls_DisplayValue = loo_JResp.StringOf("records[i].fields.AccountId.displayValue")
    ls_Value = loo_JResp.StringOf("records[i].fields.AccountId.value")
    ls_IdDisplayValue = loo_JResp.StringOf("records[i].fields.Id.displayValue")
    ls_IdValue = loo_JResp.StringOf("records[i].fields.Id.value")
    ls_NameDisplayValue = loo_JResp.StringOf("records[i].fields.Name.displayValue")
    ls_NameValue = loo_JResp.StringOf("records[i].fields.Name.value")
    ls_Id = loo_JResp.StringOf("records[i].id")
    ls_LastModifiedById = loo_JResp.StringOf("records[i].lastModifiedById")
    ls_LastModifiedDate = loo_JResp.StringOf("records[i].lastModifiedDate")
    ls_RecordTypeId = loo_JResp.StringOf("records[i].recordTypeId")
    ls_RecordTypeInfo = loo_JResp.StringOf("records[i].recordTypeInfo")
    ls_SystemModstamp = loo_JResp.StringOf("records[i].systemModstamp")
    li_WeakEtag = loo_JResp.IntOf("records[i].weakEtag")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/ui-api/records/:RECORD_ID/child-relationships/:RELATIONSHIP_NAME

Postman Collection Item JSON

{
  "name": "Get Child Records",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/records/:RECORD_ID/child-relationships/:RELATIONSHIP_NAME\n",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "ui-api",
        "records",
        ":RECORD_ID",
        "child-relationships",
        ":RELATIONSHIP_NAME\n"
      ],
      "query": [
        {
          "key": "fields",
          "value": "",
          "description": "Specifies the fields to return. If this property is specified, the response is a union of fields and optionalFields.\nIf the context user doesn’t have access to a field, an error is returned.\n\nIf you’re not sure whether the context user has access to a field and you don’t want the request to fail if they don’t, use the optionalFields parameter.\n\nSpecify names in the format ObjectApiName.FieldName. You can get any field that has a named relationship to this record. There is no limit to the number of fields you can specify.",
          "disabled": true
        },
        {
          "key": "optionalFields",
          "value": "",
          "description": "A collection of optional field names. If a field is accessible to the context user, it’s included in the response. If a field isn’t accessible to the context user, it isn’t included in the response, but it doesn’t cause an error.\nSpecify names in the format ObjectApiName.FieldName. You can get any field that has a named relationship to this record. There is no limit to the number of fields you can specify.",
          "disabled": true
        },
        {
          "key": "page",
          "value": "",
          "description": "The page offset from which to begin returning records. The default value is 0, which returns records from the first page. For example, for page=2 and pageSize=10, the first record returned is the 21st record in the list.",
          "disabled": true
        },
        {
          "key": "pageSize",
          "value": "",
          "description": "The maximum number of child records to return on a page. The default value is 5.",
          "disabled": true
        },
        {
          "key": "pageToken",
          "value": "",
          "description": "A token that represents the page offset.",
          "disabled": true
        }
      ],
      "variable": [
        {
          "key": "RECORD_ID",
          "value": "",
          "description": "Record ID"
        },
        {
          "key": "RELATIONSHIP_NAME\n",
          "value": "",
          "description": "API name of the relationship"
        }
      ]
    },
    "description": "Get child records for a specified record and child relationship name. Relationships are connections between records. On a record detail page, each record in a related list has a child relationship to the parent record."
  },
  "response": [
    {
      "name": "Get Child Records",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/records/:RECORD_ID/child-relationships/:RELATIONSHIP_NAME\n",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "ui-api",
            "records",
            ":RECORD_ID",
            "child-relationships",
            ":RELATIONSHIP_NAME\n"
          ],
          "query": [
            {
              "key": "fields",
              "value": "",
              "description": "Specifies the fields to return. If this property is specified, the response is a union of fields and optionalFields.\nIf the context user doesn’t have access to a field, an error is returned.\n\nIf you’re not sure whether the context user has access to a field and you don’t want the request to fail if they don’t, use the optionalFields parameter.\n\nSpecify names in the format ObjectApiName.FieldName. You can get any field that has a named relationship to this record. There is no limit to the number of fields you can specify.",
              "disabled": true
            },
            {
              "key": "optionalFields",
              "value": "",
              "description": "A collection of optional field names. If a field is accessible to the context user, it’s included in the response. If a field isn’t accessible to the context user, it isn’t included in the response, but it doesn’t cause an error.\nSpecify names in the format ObjectApiName.FieldName. You can get any field that has a named relationship to this record. There is no limit to the number of fields you can specify.",
              "disabled": true
            },
            {
              "key": "page",
              "value": "",
              "description": "The page offset from which to begin returning records. The default value is 0, which returns records from the first page. For example, for page=2 and pageSize=10, the first record returned is the 21st record in the list.",
              "disabled": true
            },
            {
              "key": "pageSize",
              "value": "",
              "description": "The maximum number of child records to return on a page. The default value is 5.",
              "disabled": true
            },
            {
              "key": "pageToken",
              "value": "",
              "description": "A token that represents the page offset.",
              "disabled": true
            }
          ],
          "variable": [
            {
              "key": "RECORD_ID",
              "value": "001B000000UnQ2wIAF",
              "description": "Record ID"
            },
            {
              "key": "RELATIONSHIP_NAME\n",
              "value": "Contacts",
              "description": "API name of the relationship"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 27 Sep 2023 15:57:35 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    \"count\": 1,\n    \"currentPageToken\": \"1;5;001B000000UnQ2wIAF;Contacts;Contact.Id,Contact.Name;\",\n    \"currentPageUrl\": \"/services/data/v58.0/ui-api/records/001B000000UnQ2wIAF/child-relationships/Contacts?fields=Contact.Id%2CContact.Name&page=1&pageSize=5\",\n    \"nextPageToken\": null,\n    \"nextPageUrl\": null,\n    \"previousPageToken\": null,\n    \"previousPageUrl\": null,\n    \"records\": [\n        {\n            \"apiName\": \"Contact\",\n            \"childRelationships\": {},\n            \"eTag\": \"c3d33add9008aed557a1efa68173aa9b\",\n            \"fields\": {\n                \"AccountId\": {\n                    \"displayValue\": null,\n                    \"value\": \"001B000000UnQ2wIAF\"\n                },\n                \"Id\": {\n                    \"displayValue\": null,\n                    \"value\": \"003B00000097MToIAM\"\n                },\n                \"Name\": {\n                    \"displayValue\": null,\n                    \"value\": \"Jack Rogers\"\n                }\n            },\n            \"id\": \"003B00000097MToIAM\",\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}"
    }
  ]
}