+ Start a Discussion
prasanth sfdcprasanth sfdc 

Rest API test class issue, kindly help for callout exception

  I am getting this error if i run the test class. Kindly help me to solve this, i tried for around 4 hours to solve this but, not to do.

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
private class ProjectCalloutServiceTest {

  public static void setupData() {
         // ProjectCalloutServiceTestData testdata = new ProjectCalloutServiceTestData();
         account acc = new account(name='testing acc');
        insert acc;
        opportunity opp1 = new opportunity(name='testing',closedate=date.today(),amount=200,accountid=acc.id,StageName='closed won');
        insert opp1;
        ServiceTokens__c token= new ServiceTokens__c(name='ProjectServiceToken',Token__c='a9b50c09-a94b-4826-9aa6-64407574cad6');
        insert token;
   public static void testPostCallout() {
        list<id> oppidslst = new list<id>();
        for(opportunity opp:[select id,name from opportunity where accountid!=null])
      Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMock());  

VinayVinay (Salesforce Developers) 
Hi Prasanth,

Review below links which can help you.


KI: https://success.salesforce.com/issues_view?id=a1p3A000000ATF1QAO

Vinay Kumar
prasanth sfdcprasanth sfdc
Hi Vijay, Thank you for reply. It just got fixed. The problem is the same criteria record is going for execution and same record I am calling for call-out. That's why this error happened.
VinayVinay (Salesforce Developers) 
Hi Prasanth,

Good to know issue is fixed now.

Please mark as Best Answer if above information was helpful so that it can help others in the future.

Vinay Kumar