Skip to main content

Questions tagged [httpcalloutmock]

The HttpCalloutMock interface enables sending fake responses when testing HTTP callouts in Salesforce.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

How to write test class for future httpcallout which is written [duplicate]

I have a class when QuoteAwsAccountId Object is created or AwsAccountId value inside the QuoteAwsAccountd object which is a string then it should make a get call to external api using Named ...
surya k's user avatar
-2 votes
1 answer
54 views

How to write test class for httpcallout which is written in queueable interface

I have a class when QuoteAwsAccountId Object is created or AwsAccountId value inside the QuoteAwsAccountd object which is a string then it should make a get call to external api using Named ...
surya k's user avatar
-2 votes
1 answer
107 views

Getting System.TypeException: Methods defined as TestMethod do not support Web service callouts

I have implemented everything properly but still I am getting this error. Give you my code for your reference. Please help me. //code for Combined_Test @isTest private class Combined_Test { @...
karan bilakhiya's user avatar
0 votes
0 answers
35 views

Test method throws Script-thrown exception during multi-endpoint callout [duplicate]

I have a test method that is throwing a Script-thrown exception at the line where a callout is being made. I am not sure what is the problem, I am using a mock class and validating which endpoint is ...
Mauricio.Ramos1979's user avatar
0 votes
0 answers
45 views

Methods defined as TestMethod do not support Web service callouts even when using Test.setMock

I'm working on a SOAP integration and everything is working fine but I'm facing this error in the test class even when I'm using Test.setMock. I read in some forum that the callout could be executing ...
Josue0117's user avatar
1 vote
1 answer
138 views

http call out to an external REST webservice

Simple use case - make a http call out to an external REST webservice. Parse the JSON response. I know I could do this using Flow, but due to the business requirement have opted for Apex Class. Can ...
Cloud Rizon's user avatar
-1 votes
1 answer
54 views

HttpCalloutMock for string response

The response from my API call is a csv from a url: UniCode;Purchased Date;City 12343;12/04/2000;London 12344;12/04/2003;London How can I create a HttpCalloutMock and setBody to replicate that? I keep ...
user84162's user avatar
0 votes
0 answers
49 views

Test class for @future method called by trigger not working (Methods defined as TestMethod do not support Web service callouts) [duplicate]

I have a trigger on Account that makes a call to an apex class: trigger AccountAddressTrigger on Account (after insert) { Id patientAccountRecordTypeId = [SELECT Id, RecordType.DeveloperName FROM ...
happyLion's user avatar
1 vote
0 answers
246 views

HttpCalloutMock returning null response in Test class

I've a service class that makes a callout to specific endpoint inside a future method. The callout is made on after update trigger on Contact when a relevant field update is done. @future(callout=...
Aslah P Hussain's user avatar
3 votes
1 answer
3k views

How to write an APEX Test Class with Multiple Http Callouts (Renamed)

I'm relatively new to programming, and I am attempting to write the Test Class for an Apex Class that has an HTTP Callout. I have already created the HTTP Mock Class to simulate the Callout, but when ...
nigeldendy's user avatar
1 vote
1 answer
1k views

System.JSONException: Unexpected character ('S' (code 83))

I am trying to write a test class for my rest resource and I keep getting a failure with the above error message. I've seen other anwsers suggest that there may be a '' escape character in the text, ...
Ryan Neel's user avatar
0 votes
1 answer
63 views

I cannot find the post method when doing a httpcallout through flows

I am trying to convert an opportunity to sales agreement through HTTPCallOut Action using flows and it does not give me an option to select the POST method, it only has the GET method. I created a ...
bb21's user avatar
  • 1
0 votes
0 answers
124 views

How to Create a Test class with a Future Callout that is not dependent on an HTTP Response?

I am new to Apex, but I have been tasked with sending a Salesforce Custom Object to another Company system. My Class works as expected, but my test class fails due to having a @future method. I did ...
nigeldendy's user avatar
-2 votes
1 answer
42 views

we need to have flexibly to connect any salesforce org by entering user id and password (credentials )

there is a requirement in my project i.e.. we need to integrate the target salesforce org form source org (salesforce). in this process I have gone through many documents which are available in ...
Mohammad Noushad's user avatar
1 vote
1 answer
406 views

Why Test.setMock() is not working in case of static resource?

Test.setMock() is not working Error: Method does not exist or incorrect signature: void setMock(System.Type, System.StaticResourceCalloutMock) from the type test Source Code: @isTest private class ...
ZeroX's user avatar
  • 21
0 votes
1 answer
979 views

Is Test.isRunningTest() needed to prohibit an apex test from performing a callout even if you use Test.setMock()?

Taking into consideration the below pseudo code, do we need to check if an apex test is running before performing callout? Or does the Test.setMock() method automatically prevent callouts during a ...
parkerbbrown's user avatar
0 votes
1 answer
146 views

Help with test class on

I need help to get more code coverage for the test class but I'm not sure how to approach it Class: public class salesforcetoJiraHandler { public static void newmed ( List<...
Gerson Baires's user avatar
1 vote
0 answers
46 views

How to mock/repoint urls to external services of already released managed package to different testing envs (e.g. qa/staging/uat heroku apps)

Our managed package uses a lot of external services in a form of nodejs heroku applications. Integrations are implemented in different ways: apex callout + named credentials canvas connected app ...
wesaw's user avatar
  • 3,140
0 votes
1 answer
391 views

How can I mock Twilio's Apex callout to send a SMS?

The official documentation from Twilio does not specify how to mock the calls from their managed package (with namespace "TwilioSF"). How can I mock a callout like this one? TwilioSF....
Renato Oliveira's user avatar
1 vote
1 answer
236 views

Test.loadData executeBatch Unexpected Exception

I'm writing some test cases for a custom class that interacts with a custom LWC that requires fields from SF contacts. I'm attempting to load test data from a static resource using Test.loadData as ...
Nicholas Shepard's user avatar
0 votes
1 answer
1k views

How to set StatusCode on Test.setMock [duplicate]

I have a simple class that just calls the generic HTTPCallOUt method for its test class. I want it to be able to fail in order to catch all the code. Here is my code: Test.startTest(); Test....
Simple Code's user avatar
0 votes
1 answer
439 views

Test class for HTTPCallout POST with Invocable Method from Flow [duplicate]

I'm still pretty new to this, and I've looked around and haven't been able to find the solution that combines everything like I'm trying to do. I've tried quite a few things, but here's where I ...
OmniMacchiato's user avatar
0 votes
1 answer
2k views

Test Class Error - System.QueryException: List has no rows for assignment to SObject json | Cover JsonGenerator in Test Class

"Hello everyone" I have a week with this problem in the testClass. So the problem is the following: System.QueryException: List has no rows for assignment to SObject json. The problem comes ...
Alex Barón's user avatar
2 votes
1 answer
289 views

Constructor chaining giving method not defined

I have the following class with constructor chaining , but the validations are returning Method not found or incorrect signature class @IsTest global class CalloutMock implements HttpCalloutMock { ...
Akash Jain's user avatar
0 votes
1 answer
3k views

The Test.isRunningTest() function is not working

I am using if(Test.isRunningTest()) condition to set the response code to 200 for code coverage related to my HTTP callout class, so that the success scenario gets covered. But in the coverage details ...
Akshay Vasu's user avatar
0 votes
1 answer
563 views

Test class for queueable apex trigger handler with http callout

Whenever a new record of object abc is created, a queueable trigger handler makes http callout. My trigger handler is working fine and i am able to do what I intended, but when I test this trigger ...
jaiso's user avatar
  • 25
0 votes
1 answer
628 views

how to test the Rest Callout using Stub API

Hi Greetings for the day. using the below code ,I have test the Rest callouts by using Stub API .Test class has been completed with out failure but received code coverage Zero.how to test the Rest ...
sakthidasan's user avatar
0 votes
0 answers
2k views

Document.load() fails: System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag and not {

I am getting the following error when tying to use the Document.load() method for my xml: System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag and not { (...
robruf's user avatar
  • 382
0 votes
0 answers
1k views

Test Class of batch Apex which includes a Http Callout in the execute method

I'm stuck trying to create a Test class for my batch which execute a Http request. I tried with Test.setMock and also inserted "!Test.isRunningTest()" in the batch but nothing changes. I ...
Sandra 's user avatar
2 votes
1 answer
824 views

Test Class with HttpMockCallout is throwing error

I am trying todo the Super Badge for the Data Integration Specialist. I wrote the Apexcall that will connect to the external system and send out the opportunity information. When trying to write the ...
user81642's user avatar
  • 687
1 vote
1 answer
4k views

Testing a class that has multiple callouts?

What is the best practice for writing apex test classes where you have multiple callouts? My Test Class would then be testing the secondCallout method which happens to also call a firstCallout method ...
jojopogi's user avatar
  • 532
1 vote
2 answers
560 views

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) ...
jojopogi's user avatar
  • 532
0 votes
0 answers
41 views

Problem with Apex HTTP callout POST Test [duplicate]

I get the following error: "System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out" when executing my test. The code coverage is already at ...
Josue Rivas's user avatar
0 votes
1 answer
126 views

Problem with testing void HttpRequest

I can only get 23% code coverage with what I have. The http request in the method is not getting covered for some reason.. Here's what I've tried: Class: public class PostClientes { @...
Josue Rivas's user avatar
7 votes
1 answer
3k views

Can we Have two Http Mock Callouts in a single test class method

In My Method making two callouts in a single transaction Get Access Token For that API --> GetAccessToken Execute Payment When i ran the test class getting following error 08:50:00:839 ...
SFDC_Beginner's user avatar
0 votes
0 answers
18 views

Test Class for mulitple Callouts [duplicate]

I have the apex class that makes the call to two endpoints in the same method like below @future (callout=true) public static void createSegSubSegment(String jsonBody,String endPoint) { String ...
user81642's user avatar
  • 687
0 votes
1 answer
2k views

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 ...
user81642's user avatar
  • 687
14 votes
2 answers
870 views

Salesforce 2020 release has blocked all Apex tests that use http mocking

We have 100+ tests failing now that our main testing sandbox has received the 2020 release. We can no longer deploy. We're getting many errors like Unexpected error: You have uncommitted work ...
Andy Ray's user avatar
  • 1,488
5 votes
0 answers
195 views

Test fails with runAs, queueable and callout in specific org

Has anyone got an idea what could cause the following test to fail in one org and pass in another? The error is System.CalloutException: You have uncommitted work pending. Please commit or rollback ...
James's user avatar
  • 2,649
0 votes
0 answers
64 views

You have uncommitted work pending - apex test with three callouts

I am trying to create a test where there are three (mocked) callouts to a web service which then creates or updates records. Within my test class if I try to run the callout/update code twice within ...
eaeaoo's user avatar
  • 928
-1 votes
1 answer
237 views

Test class for Http Request code coverage is 50 percent [duplicate]

I have a class public class myclass { @AuraEnabled public static List <Json2Apex> customerData(String startDate, String enddate){ List <Json2Apex> LSData = new List &...
Padam's user avatar
  • 55
2 votes
2 answers
3k views

How to test a Platform Event Trigger that makes callout(s)?

I am integrating with a third-party API that calls an unauthenticated webhook (HTTP Post) that I have implemented with a small payload; my code then uses that payload to make an authenticated call to ...
Jason Clark's user avatar
1 vote
0 answers
83 views

'uncommitted work pending' callout exception thrown in *tests only*

I am converting a lead in the Execute method of a batch class, then making 2 callouts with those results in the Finish() method. It works gloriously and throws no errors. However, in the test ...
Mobot818's user avatar
  • 142
1 vote
0 answers
34 views

Correctly Write Test and Callout test on trigger [duplicate]

I have a trigger on Account after insert and after update. In both cases I need to call my BUS to update in the compagny database. Since I will have to deploy my dev into QA I need to write a test ...
Benoît S's user avatar
0 votes
0 answers
100 views

Test.setMock working in Scratch org but not in sandbox Org

We have batch class used to make an API callout and doing Opportunity upsert DML operation in the Start method. Based on the opportunity's return value, we are making another API callout and doing ...
user10286's user avatar
  • 422
0 votes
2 answers
662 views

mock test class and test class for 2 classes

I have 2 class A and B. A has code for Http Callout and from B we are calling A's class method which has callout code. So should we write mock test class for A only or do we have to write mock test ...
Anoop's user avatar
  • 47
8 votes
1 answer
2k views

How can I unit test a http callout that uses a certificate?

The .setClientCertificateName method of the HttpRequest class requires a string that is the name of a certificate in the organization. In a unit test class, is it possible to mock this method? When I ...
Renato Oliveira's user avatar
0 votes
1 answer
354 views

Rest Callout Apex Test: How to Test @AuraEnabled Method?

guys! I have a problem with one method in my Apex class, which I need to cover by tests. This class uses "GET" callout and checks, if the input field is empty (null). If it is, the @AuraEnabled ...
LostSoul325's user avatar
0 votes
1 answer
630 views

Rest Callout Test Class : How to Cover @AuraEnabled method?

I'm new to Salesforce and now I'm struggling with one task. I need to make test class, but I'm wondering: how do you cover the second @auraEnabled method with If statement? Here is the code: Apex ...
LostSoul325's user avatar
1 vote
1 answer
229 views

Can I query custom metadata type record in a HttpCalloutMock?

I am trying to understand if I can make use of Custom Metadata Type record by quering it in a HttpCalloutMock this way: public HTTPResponse respond(HTTPRequest request) { String myString = [Select ...
Austin Evans's user avatar