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
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',,amount=200,,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.


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