You need to sign in to do that
Don't have an account?
KR_Force
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Class.TestEvalEndDateHTTPCallOut.testEVAlEndDateCallout: line 28, column 1
- @isTest
- public class TestEvalEndDateHTTPCallOut {
- public static testmethod void testEVAlEndDateCallout() {
- SingleRequestMock fakeResponse = new SingleRequestMock(200,
- 'Complete',
- '[{"Name": "sForceTest1"}]',
- null);
- Test.setMock(HttpCalloutMock.class, fakeResponse);
- set<ID> ast=new Set<ID>();
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- insert a1;
- ast.add(a1.id);
- Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
- insert foo;
- Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
- Insert c;
- PageReference pageRef = Page.RefreshEvalEndDate;
- Test.setCurrentPage(pageRef);
- Apexpages.StandardController stdController = new Apexpages.StandardController(a1);
- Apexpages.currentPage().getParameters().put('id',a1.Id);
- EvalEndDateHTTPCallOut controller = new EvalEndDateHTTPCallOut(StdController);
- controller.parseJSONResponse();
- EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
- }
- }
This error occur when you are inserting any record before any callout. You have to callout first then call any DML operation.
To make the call out i need to pass the asset record to main method, with out test being created how can i make a call out?
if undertood wrong can you please share some sample code which helps me to build my test class?
thanks for your help!
I think Ashlekh has deleted his post.
See below code
Starttest and stoptest did help to fix callout exception but now running into "System.TypeException: Invalid conversion from runtime type LIST<ANY> to MAP<String,ANY>" error at line 31. any suggestions?