I found many resources available on stackexchange regarding this issue. We cannot make a callout after doing any dml. But i do not think i am doing any DML operation in my code.
Logical flow of my code is: Create/Update account in Org 2 > Process Builder is invoked and in turn it calls apex class(AccountManagerRest.AccountMigrator(list of IDs)), passing Account Ids > Calling a rest resource Post method to create/update account in Org 1.
Error : We can't save this record because the “Account Migrator” process failed. Give your Salesforce admin these details. An Apex error occurred: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Error ID: 988335765-184809 (1313514187) .
Apex class: Pasting code here.
Rest Service: Pasting code here.
Is internally any DML is being called? Because i read here that process builder invokes after saving the record, at step #14.
Any suggestions on how to tackle this problem. Thanks.