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
rupesh ranjanrupesh ranjan 

Error Message System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Stack Trace Class.homeReport.getperformcallout:

Error Message	System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Stack Trace	Class.homeReport.getperformcallout: 



@isTest(seeAllData = false)
public class homeReportTests
{
   
  static testmethod void Myunittest1()
    {
       Account account = new Account();
       account.Name = 'Accc';
       insert account;   
       Contact contact = new Contact();
       contact.FirstName = 'rup';
       contact.LastName = 'ran';
       contact.AccountID = account.Id;
       contact.Email = 'rup.ran@gmail.com';
       contact.MobilePhone = '918527116725';
       insert contact;
       homeReport cp = new homeReport(new ApexPages.StandardController(contact));
      Test.startTest();
       Test.setMock(HttpCalloutMock.class, new homepagemock());     
       homeReport testAObj = new homeReport();
       testAObj.getperformcallout();
      HttpResponse res = new HttpResponse();
      String actualValue = res.getBody();
        String expectedValue = '{"foo":"bar"}';
     System.assertEquals(actualValue, expectedValue);
       System.assertEquals(200, res.getStatusCode());
        cp.getperformcallout(); 
        Test.stopTest(); 
    } 
  
}

 
James LoghryJames Loghry
Rupesh,  more specifics of your issue would be helpful.

Generally speaking, try moving the Test.setMock before Test.startTest();

If that doesn't fix your issue, then you are calling an insert, update, or delete in either the homereport constructor or the getperformcallout method, pior to making a web service callout.

This DML action (insert,update,delete) could be a result of an error condition, so make sure you check those as well.

Hope that helps,