Object A has multiple child records of object B (about 10 000).
The requirement is to send the whole object A including all records of object B when a checkbox field is set to TRUE on object A. This means a maximum of 10 001 records to be sent to an external system.
Now the problem is that 10 001 records will exceed the heap size limit and I'd like to split the records to be sent for example in batches of 2 000, but if any of those batches fail to be sent (the external service returns 400 Bad Request for example as a response to one of the calls), I need to terminate the transaction and not send anything more and somehow later identify that the object A with object B needs to be resent in a retry mechanism.
I was thinking I could make a custom staging object, where I would create a record for each integration to be fired, so the checkbox on object A would change and I would create a record with the ID of the object A and also the status of the integration.
However, I don't know if it possible in Salesforce to make a continuation of callouts where the records would be split by for example OFFSET in the query. The only continuation reference I could find in the documentation was for Lightning Web Components. I need this to be fired from a trigger.
What I can not do:
- Move this integration to a middleware (the integration has to be outbound from Salesforce to external system)
- Send only the changes (all the record A and records B have to be sent)
Kindly asking for some advice.