I am creating a custom REST API that receives as input the following structure:
- Subscription record (main record)
- Order Product record (Parent of Subscription)
I want to update the Subscription record and also the Order Product record. However, i cannot access the "csord__Order_Product__r" information of the given request.
Sample Request:
{
"inputSub": {
"name": "My Test Subscription record",
"Id": "a0c1l000002KATkAAO",
"csord__Order_Product__r": {
"Id": "a0T1l000005ACEDEA4",
"name": "Test Order Product",
"el_Status_Reason__c": "Cancellation"
}
}
}
APEX Code:
@HttpPut global static getSubscriptionInformation doPost(csord__Subscription__c inputSub){
system.debug('input is: ' +inputSub);
getSubscriptionInformation result = new getSubscriptionInformation();
try {
update inputSub; //update Subscription record
update inputSub.csord__Order_Product__r; //update related Order Product record
result.orderProductResult.Subscription = inputSub;
return result;
} catch (Exception e) {
system.debug('Exception: ' +e.getMessage());
result.error_code = '1';
result.error_message = e.getMessage();
}
return result;
}
- Can i somehow access the "parent" element from the given request and update it?
- Should i change the structure in order to always get the parent record and then the child?