How to do Transaction Management using adapter

Hi All,

We are using adapter to transfer data to CRM. We have a requirement to insert data into Detail tables only if insertion into Header table succeeds. So we are using startTransaction, commitTransaction & rollbackTransaction to control the transactions. But it is failing to rollback the data being inserted into Salesforce.

Below is the sample code showing insertion and throwing error after insertion to test rollback. But it is not working and failing to rollback the data being inserted into Salesforce.

Main Sequence
Try Sequece
insertAccount → Inserts account data into Account sObject in
throwError → Throws an exception to test whether rollback is working
or not

Catch Sequence

Can you please let me know how to do Transaction management using Adapter and let me know if you have any questions on the same.

Pradeep Kumar K

You can try to put the ‘startTransaction’ outside the sequence (or)
bring the rollBack transaction as another sequence within the try block


I looked into using this adapter a few years ago, and back then, transactions were not supported. The reason given was that “the adapter uses the partner WSDL and the APIs support only single sObject.” In simpler words, the adapter talks to via web service calls and each web service call only acts on a single object/table. Once a call is done, it’s done. It has no relationship to future calls.

I’m not sure if things have changed since then. If they haven’t, a common work-around for an issue like this is to insert into the detail table first and then the header. This is done because the data consumers normally query the header table first so by the time the header record is inserted, you already know the detail records succeeded. You will still have the issue that if, for example, the header record fails, you will want to rollback the detail changes. Unfortunately, in that case, your only choice may be to perform a delete (assuming you did an insert earlier) and hope it works.

  • Percio