Chilkat Online Tools

delphiDll / Salesforce Platform APIs / Lookup Table

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
errorCode: PWideChar;
errorMessage: PWideChar;
outcomeType: PWideChar;
successStatus: Boolean;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "conditions": {
//     "conditionsList": [
//       {
//         "fieldName": "IsDeleted",
//         "value": true
//       }
//     ]
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'conditions.conditionsList[0].fieldName','IsDeleted');
CkJsonObject_UpdateBool(json,'conditions.conditionsList[0].value',True);

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

resp := CkHttp_PostJson3(http,'https://domain.com/services/data/v{{version}}/connect/business-rules/decision-table/:decisionTableId','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

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

// {
//   "errorCode": null,
//   "errorMessage": null,
//   "outcomeList": [
//   ],
//   "outcomeType": "No Match",
//   "successStatus": true
// }

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

errorCode := CkJsonObject__stringOf(jResp,'errorCode');
errorMessage := CkJsonObject__stringOf(jResp,'errorMessage');
outcomeType := CkJsonObject__stringOf(jResp,'outcomeType');
successStatus := CkJsonObject_BoolOf(jResp,'successStatus');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'outcomeList');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "conditions": {
        "conditionsList": [
            {
                "fieldName": "IsDeleted",
                "value": true
            }
        ]
    }
}'
https://domain.com/services/data/v{{version}}/connect/business-rules/decision-table/:decisionTableId

Postman Collection Item JSON

{
  "name": "Lookup Table",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"conditions\": {\n        \"conditionsList\": [\n            {\n                \"fieldName\": \"IsDeleted\",\n                \"value\": true\n            }\n        ]\n    }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/connect/business-rules/decision-table/:decisionTableId",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "connect",
        "business-rules",
        "decision-table",
        ":decisionTableId"
      ],
      "variable": [
        {
          "key": "decisionTableId",
          "value": "0lDHo0000008Pnt",
          "description": "Decision Table Id"
        }
      ]
    },
    "description": "# Decision Table (Lookup Table)\n\nPerforms a lookup on a decision table.Resource\n\n```\n/connect/business-rules/decision-table/${decisionTableId}\n\n ```\n\nResource Example\n\n```\nhttps://yourInstance.salesforce.com/services/data/v55.0/connect\n/decision-table/0lDB0000000TNQzMAO\n\n ```\n\nAvailable version\n\n55.0\n\nRequires Chatter\n\nNo\n\nHTTP methods\n\nPOST\n\nRequest body for POST\n\nJSON example\n\n```\n{\n   \"conditions\" : {\n      \"conditionsList\" : [\n         {\n            \"fieldName\": \"state__c\",\n            \"value\": \"MH\"\n         },\n         {\n            \"fieldName\": \"validity__c\",\n            \"value\": 30\n         }\n      ]\n   }\n}\n\n ```\n\nProperties\n\n| Name | Type | Description | Required or Optional | Available Version |\n| --- | --- | --- | --- | --- |\n| conditions | [Decision Table Condition](https://developer.salesforce.com/docs/atlas.en-us.industries_reference.meta/industries_reference/connect_requests_decision_table_condition.htm)\\[\\] | The list of decision table conditions on which the decision table executes and provides outcomes. | Required | 55.0 |\n| datasetLinkName | String | The API name of the dataset link provided as an input for the decision table execution. | Optional | 55.0 |\n\nResponse body for POST\n\n[Decision Table Outcome](https://developer.salesforce.com/docs/atlas.en-us.industries_reference.meta/industries_reference/connect_responses_decision_table_outcome.htm)\n\n# Decision Table Outcome\n\nOutput representation of the decision table execution.JSON example\n\n```\n{\n  \"errorCode\" : null,\n  \"errorMessage\" : null,\n  \"outcomeList\" : [ {\n    \"values\" : {\n      \"amount__c\" : \"399\",\n      \"Name\" : \"MH 005\"\n    }\n  }, {\n    \"values\" : {\n      \"amount__c\" : \"499\",\n      \"Name\" : \"MH 006\"\n    }\n  }, {\n    \"values\" : {\n      \"amount__c\" : \"379\",\n      \"Name\" : \"MH 007\"\n    }\n  }, {\n    \"values\" : {\n      \"amount__c\" : \"1498\",\n      \"Name\" : \"MH 008\"\n    }\n  }, {\n    \"values\" : {\n      \"amount__c\" : \"98\",\n      \"Name\" : \"MH 009\"\n    }\n  }, {\n    \"values\" : {\n      \"amount__c\" : \"251\",\n      \"Name\" : \"MH 010\"\n    }\n  } ],\n  \"outcomeType\" : \"Multiple Matches\",\n  \"successStatus\" : true\n}\n\n ```\n\n| Property Name | Type | Description | Filter Group and Version | Available Version |\n| --- | --- | --- | --- | --- |\n| errorCode | Integer | The error code if transaction fails for any reason. | Small, 55.0 | 55.0 |\n| errorMessage | String | The error message if transaction fails for any reason. | Small, 55.0 | 55.0 |\n| outcomeList | [Decision Table Outcome Item](https://developer.salesforce.com/docs/atlas.en-us.industries_reference.meta/industries_reference/connect_responses_decision_table_outcome_item.htm)\\[\\] | Outcome list that stores two or more outcomes provided by the decision table. | Small, 55.0 | 55.0 |\n| outcomeType | String | The outcome type after the request is successful. | Small, 55.0 | 55.0 |\n| successStatus | Boolean | Indicates the status of the decision table execution. | Small, 55.0 | 55.0 |"
  },
  "response": [
    {
      "name": "Status400-BadRequest",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"conditions\": {\n        \"conditionsList\": [\n            {\n                \"fieldName\": \"state__c\",\n                \"value\": \"MH\"\n            },\n            {\n                \"fieldName\": \"validity__c\",\n                \"value\": 30\n            }\n        ]\n    }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/connect/business-rules/decision-table/:decisionTableId",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "connect",
            "business-rules",
            "decision-table",
            ":decisionTableId"
          ],
          "variable": [
            {
              "key": "decisionTableId",
              "value": "0lIHo000000LFC6MAO",
              "description": "Decision Table Id"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Tue, 19 Sep 2023 12:16:33 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": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"errorCode\": \"INVALID_ID_FIELD\",\n        \"message\": \"Invalid identifier: 0lIHo000000LFC6MAO\"\n    }\n]"
    },
    {
      "name": "Status500-UnknownException",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"conditions\": {\n        \"conditionsList\": [\n            {\n                \"fieldName\": \"Comment Count\",\n                \"value\": 1\n            }\n        ]\n    }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/connect/business-rules/decision-table/:decisionTableId",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "connect",
            "business-rules",
            "decision-table",
            ":decisionTableId"
          ],
          "variable": [
            {
              "key": "decisionTableId",
              "value": "0lDHo0000008PnjMAE",
              "description": "Decision Table Id"
            }
          ]
        }
      },
      "status": "Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Tue, 19 Sep 2023 12:31:01 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": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"message\": \"An unexpected error occurred. Please include this ErrorId if you contact support: 1716762391-743375 (1633993601)\",\n        \"errorCode\": \"UNKNOWN_EXCEPTION\"\n    }\n]"
    },
    {
      "name": "Status201-Success",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"conditions\": {\n        \"conditionsList\": [\n            {\n                \"fieldName\": \"IsDeleted\",\n                \"value\": true\n            }\n        ]\n    }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/connect/business-rules/decision-table/:decisionTableId",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "connect",
            "business-rules",
            "decision-table",
            ":decisionTableId"
          ],
          "variable": [
            {
              "key": "decisionTableId",
              "value": "0lDHo0000008Pnt",
              "description": "Decision Table Id"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Tue, 19 Sep 2023 13:22:05 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    \"errorCode\": null,\n    \"errorMessage\": null,\n    \"outcomeList\": [],\n    \"outcomeType\": \"No Match\",\n    \"successStatus\": true\n}"
    }
  ]
}