I am working on a web service callout in Apex which returns some child data for the Asset object. I can represent a class to depict the structure of the data that I am receiving.
[{
"Id": "02i0000000000000C",
"options": [{
"name": "Conference Event",
"startDate": "2019-01-01T00:00:00.000Z",
"EndDate": "2023-01-01T00:00:00.000Z"
},
{
"name": "Drama",
"startDate": "2023-01-01T00:00:00.000Z",
"EndDate": "2024-01-01T00:00:00.000Z"
},
{
"name": "Magic Show",
"startDate": "2020-01-01T00:00:00.000Z",
"EndDate": "2022-01-01T00:00:00.000Z"
}
]
}]
The options is a child object of Asset with the name Asset_Options__c. I need to query to Asset_Options__c for a given asset and compare the data with the above response and update Asset_Options__c records and I am not sure what is the best way to proceed. There is no need to consider the time portions of the date while comparing. However, whatever is coming from the web service response should overwrite what is available in the Asset_Options__c object in Salesforce. In short, below are the three scenarios:
Update Scenario
For ex, if the Asset_Option__c record for "Magic Show" has the start date of "2018-01-01T11:11:11.000Z" in Salesforce, it should be over written with the value coming from webservice response (2020-01-01T00:00:00.000Z).
Insert Scenario
Also, if an option that is coming from webservice is not found in Asset_Options__c record, it should be inserted as a new record.
Delete Scenario
Also, if the web service response comes with "Conference Event" and "Drama" where as Asset_Options__c has all three options, the "Magic Show" record should be deleted from the Asset_Options__c object.
Can someone help?
Asset_Options__c
records and insert them again with the latest response from web service? that would cover new/updated/deleted scenarios. I don't know, might be a quick solution, but I don't know all the automations you might have in place.