-2

This is my raw return

[
  {
    "orderDetails": {
      "orderId": 12345,
      "caseName": "Smith vs Smith",
      "orderStatus": "Active Case",
      "orderedBy": "First Last",
      "patientName": "First Last",
      "orderDate": "2020-12-04 00:00:00.000",
      "orderTimeline": [
        {
          "enteredDate": "2020-12-04 10:38:22.780",
          "enteredBy": null,
          "orderEvent": "Active Case",
          "enteredRemarks": ""
        }
      ]
    },
    "providerDetails": [
      {
        "providerOrderId": "123456",
        "providerName": "25 East Same Day Surgery",
        "recordType": "Medical",
        "providerStatus": "Records Obtained",
        "enteredDate": "2020-12-04 10:38:22.780",
        "providerTimeline": [
          {
            "enteredDate": "2020-12-06 22:18:57.690",
            "enteredBy": null,
            "providerEvent": "Request New",
            "enteredRemarks": ""
          }
        ],
        "providerRecords": [
          {
            "recordType": "Medical Records",
            "enteredDate": "2020-12-04 10:38:22.780",
            "fileId": 12345,
            "fileName": "Medical Record.pdf",
            "fileSize": 12345,
            "fileType": "application/pdf",
            "fileLink": "https://www.recordboss.com/download?file_uuid=MjAyMS8yMDIxMDEvMjAyMTAxMDQvTnVyc2UgUmV2aWV3X0lDRV9SZWRhY3RlZC5wZGY=&key=MTYyMTI5NjU1NA==",
            "fileData": "<BASE64 ENCODED FILE DATA>"
          }
        ]
      }
    ]
  }
] 

I'm parsing the return like this Object orderRecords = JSON.deserializeUntyped(requestBody);

But then I get lost how I'm suppose to loop through this. Every which way I've currently tried to loop through I get errors, so now I'm to this point. I need to be able to extract orderId=12345

{orderDetails={caseName=Smith vs Smith, orderDate=2020-12-04 00:00:00.000, orderId=12345, orderStatus=Active Case, orderTimeline=({enteredBy=null, enteredDate=2020-12-04 10:38:22.780, enteredRemarks=, orderEvent=Active Case}), orderedBy=First Last, patientName=First Last}, providerDetails=({enteredDate=2020-12-04 10:38:22.780, providerName=25 East Same Day Surgery, providerOrderId=123456, providerRecords=({enteredDate=2020-12-04 10:38:22.780, fileData=<BASE64 ENCODED FILE DATA>, fileId=12345, fileLink=https://www.recordboss.com/download?file_uuid=MjAyMS8yMDIxMDEvMjAyMTAxMDQvTnVyc2UgUmV2aWV3X0lDRV9SZWRhY3RlZC5wZGY=&key=MTYyMTI5NjU1NA==, fileName=Medical Record.pdf, fileSize=12345, fileType=application/pdf, recordType=Medical Records}), providerStatus=Records Obtained, providerTimeline=({enteredBy=null, enteredDate=2020-12-06 22:18:57.690, enteredRemarks=, providerEvent=Request New}), recordType=Medical})}
1

1 Answer 1

1
Object orderRecords = JSON.deserializeUntyped(requestBody);
for (Object ob : (List<Object>)orderRecords) {
    Map<String, Object> obMap = (Map<String, Object>)ob;
    Map<String, Object> orderDetailsMap = (Map<String, Object>)obMap.get('orderDetails');

    System.debug(orderDetailsMap.get('orderId'));
}
1
  • Thank you! I've been banging my head over this trying to figure out the proper way to typecase this! Dec 13, 2021 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .