function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim FieldJim Field 

Need help with multiple transactions

I am sending Salesforce accounts to Infor M3 via an api call to ION.  After the M3 customer number is returned to Salesforce and written to the record, I need to send any related contacts to M3.  I have tried numerous ways of doing this, but I always end up with an error on the contact send.   The errors range from "you have uncommitted work pending, please commit or rollback before calling out" to "you can't call a future method from a future method."  I even tried using a business process flow to call apex to send the contacts after the account has been updated with the M3 customer number, but that also results in an "uncommitted work" error.  What is the best practice for sending a Salesforce record to an outside system and then sending any related records to the outside system?  How can I send the contacts after the account M3 customer number has been written to the Salesforce account record?
AbhishekAbhishek (Salesforce Developers) 
You may have to create a record and then update it with the information provided by a Web Service. However, a Web Service Callout may not occur after a DML statement within the same transaction. To achieve the required action, the transaction must be separated into two parts so that the DML transaction is completed before the Web Service Callout occurs.

Try the resolution as mentioned in the below official article,

https://help.salesforce.com/articleView?id=000326129&type=1&mode=1


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.