How can I return HttpResponse after calling a class which implements Queueable

As described in the title, I have a class which implements the Queueable interface, for each item it sends an http request and I would like to get the response back and use it. My problem is that I must implement the method: void System.Queueable.execute(System.QueueableContext) I was hoping to achieve something similar to: HttpResponse System.Queueable.execute(System.QueueableContext) … Read more

Does HttpCalloutMock work when the tested method doesn’t return HttpResponse?

UPDATED: I’ve included the unit test. I’m trying to test a Visualforce extension method that does a callout but returns a PageReference, not an HttpResponse. I’m finding that the HttpCalloutMock doesn’t give the expected result to the extension method. In the code example below, the try is failing, even though I’ve set the mock to … Read more

facing System.CalloutException for HTTP response in test class

I’m facing “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out” Here is my codes: (Adding only the relevant code) Callout Class which contains the response logic (getAWBResponse method): global class FreightAWBPopUpController { // Aura enabled instance variables here @AuraEnabled public static FreightAWBPopUpController getRecordUpdate(Id CaseId) { string requestJson; FreightAWBPopUpController obj = … Read more

How to avoid: Error uncommitted work pending in my testclass

I am doing do a callout trough a processbuilder with a future call. Before I do the call I get some variables from a custom setting. When I do an insert in my testclass for my custom setting I get the error System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out. … Read more

How to test access token for HTTP callouts?

I have an access token for my HTTP callouts. How can I test it if I wanna use Static Resource? But I can also use the HttpCalloutMock Interface. it doesn’t matter My access token is in custom object. I just call fields in the method. public static String accessToken(){ //Error is here: Token__c tok = … Read more

How to test ‘throw new MyException()’ in HttpResponse Callout?

I always get an Fail when try to test the negative scenario. How can I fix it? Sorry, I’m just learning. Callout: public class MyException extends Exception {} public class Token{ public String accessToken{get;set;} } public static String accessTokenBody(){ //our web token (data is in fields) Settings__c settings = [SELECT ConsumerKey__c, ClientSecret__c, Username__c, Password__c, SecurityToken__c … Read more

Test Class for the Apex Callout with OAuth

I am trying to write the Test Class for the Apex Callout which uses the OAuth. The Apex Class with the future method is like below @future (callout=true) public static void createSegSubSegment(String jsonBody,String endPoint) { String clientId = ”; String clientSecret = ”; String resource = ”; String tenant_id = ”; String bearerToken = ”; … Read more

Test Coverage for a HttpCalloutMock?

We have a test class, and it has @isTest and for some reason, salesforce is showing this class as needing coverage? Shouldn’t this class be excluded from code coverage? @isTest(seeAllData=false) global class MyMockResponse implements HttpCalloutMock{ global HTTPResponse respond(HTTPRequest request) { //some code } } Answer It doesn’t need coverage if it is annotated with @IsTest. … Read more

Unable to save Mock test class in trailhead

I’ve started learning Apex Integration Services trailhead. I’m unable to save a test class AnimalsCalloutsTest: @isTest private class AnimalsCalloutsTest { @isTest static void testGetCallout() { // Create the mock response based on a static resource StaticResourceCalloutMock mock = new StaticResourceCalloutMock(); mock.setStaticResource(‘GetAnimalResource’); mock.setStatusCode(200); mock.setHeader(‘Content-Type’, ‘application/json;charset=UTF-8’); // Associate the callout with a mock response Test.setMock(HttpCalloutMock.class, mock); // … Read more