2

I am getting the above error when I run the following test class:

     @isTest(SeeAllData=true)
    public with sharing class testCustomerSalesStatisticsController{
           public static testMethod void testCustomerSalesStatistics() {


                 Account a = new Account(Name='Tester', 
            AccountNumber='101552',
            Rating = 'Hot',
            NumberOfEmployees = 10,
            Description = 'test'
            );
            insert a;
Test.startTest();

               Test.setMock(WebServiceMock.class, new WebServiceMockImplSIS()); 
               ApexPages.StandardController sc = new ApexPages.standardController(a);
               CustomerSalesStatisticsController OD = new CustomerSalesStatisticsController(sc);
               OD.CustNo = a.AccountNumber;
            //   OD.viewSISInfo();
               OD.getSISInfo();




           **MiddleWare__c mw = [SELECT id FROM MiddleWare__c WHERE name = 'esyconnector'];
            mw.Active__c = false;
            update mw;
            MiddleWare__c mw1 = [SELECT id FROM MiddleWare__c WHERE name = 'webmethods'];
            mw1.Active__c = true;
            update mw1;


             ApexPages.StandardController sc1 = new ApexPages.standardController(a);
               CustomerSalesStatisticsController OD1 = new CustomerSalesStatisticsController(sc1);
           //     OD1.CustNo = a.AccountNumber;
                  OD1.getSISInfo();**
           Test.stopTest();
    }
    }
2
  • If you have any workflow email alerts on the account object (or any object but in your case the account) you will get this error. Could that be the case? It is a known bug
    – Eric
    Dec 11, 2015 at 23:34
  • best practice - get rid of seeAlldata=true; you or your successor may come to grief over this during a deployment. Mock all sobjects you need; only rare cases where this is required
    – cropredy
    Dec 12, 2015 at 0:31

1 Answer 1

0

In salesforce you can not make dml and then do callout. This error comes when you try do to such things. BY calling getSISInfo method you are making callout and in test class for the first time it would be okay but in the same execution you have made dmls by below part of your code.

**MiddleWare__c mw = [SELECT id FROM MiddleWare__c WHERE name = 'esyconnector'];
            mw.Active__c = false;
            update mw;
            MiddleWare__c mw1 = [SELECT id FROM MiddleWare__c WHERE name = 'webmethods'];
            mw1.Active__c = true;
            update mw1;

And again in the same transaction your are calling getSISinfo means you are making callouts after dml. If you want to solve this write separate test method to check different functionality. Make sure that you are not making dml before making any callout. Before start method if you do any dml then that would be okay since salesforce will start context from start method.

7
  • But the same worked for me properly in another test class Dec 11, 2015 at 19:01
  • @Pri Thats not possible. You can not make DML and then do a callout (unless you are using any extra workarounds to pass that.). Here is the doc which confirms that. help.salesforce.com/apex/HTViewSolution?id=000003701 Dec 11, 2015 at 19:03
  • @Pri You can check your test class error. You should be getting error at the point where you are trying to make callout after dml. Dec 11, 2015 at 19:04
  • In case if I am using my DML above the start method then I am getting System.TypeException: Collection store exception error Dec 11, 2015 at 19:13
  • @Pri At which line you are getting such error. Dec 11, 2015 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .