I have Apex code that performs a callout to an external system to insert a record. After the callout is performed a DML operation stores the resulting external ID back in an sObject.
A super simplified version would look something like this:
HttpRequest req = new HttpRequest(); req.setEndpoint('http://www.fishofprey.com/'); req.setMethod('GET'); Http http = new Http(); HTTPResponse res = http.send(req); res.getBody(); Account a1 = new Account(name='a'); insert a1;
The real call would do a POST and then use the result as part of creating the new record, but you get the idea.
This works fine in normal operation. However, when the org gets put into read-only mode the callout still occurs but the subsequent DML fails with the error
System.InvalidReadOnlyUserDmlException: Insert failed. First exception on row 0; first error: INSERT_UPDATE_DELETE_NOT_ALLOWED_DURING_MAINTENANCE, Updates can't be made during maintenance. Try again when maintenance is complete.
That's a bit of a problem, because the external system has the new record but Salesforce doesn't know about it.
How can I prevent this problem?