I am getting an exception of
System.CalloutException: You have uncommitted work pending. Detail of the Exception is given Below:
Exception: :System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
I am using Apex for calling a Webservice. Based on the data returning from the WebService, performing upsert operation in Salesforce Instance. I am performing the following operation on the Salesforce Instance.
1 Performing upsert operation in Campaign Object.
2 Performing upsert Operation in Account Object.
3 Performing upsert Object in Contact Object using AccountID of the earlier inserted Account.
4 Then Adding Contacts as CampaignMember in the Campaign that I have Created earlier.
My code is working fine when There is only one record in the Webservice API but when there are more than one record in the API then getting the Exception of System.CalloutException: You have uncommitted work pending. I have spend one week but did not able to get rid off the exception.
Any help will be much appreciated.
Thanks in advance.