Questions tagged [httpcalloutmock]
The HttpCalloutMock interface enables sending fake responses when testing HTTP callouts in Salesforce.
177
questions
1
vote
0
answers
23
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=...
1
vote
1
answer
99
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 ...
1
vote
1
answer
248
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, ...
0
votes
1
answer
54
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 ...
0
votes
0
answers
42
views
Test class for http callout doesn't work because a value within the controller method it's not populated as it should in the test method
I have this apex controller which has a method that does a POST request to captcha api. From lwc component I receive a token which I use in my method.
controller class
public with sharing class ...
0
votes
0
answers
89
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 ...
-2
votes
1
answer
35
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 ...
1
vote
1
answer
143
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 ...
0
votes
1
answer
435
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 ...
0
votes
1
answer
134
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<...
1
vote
0
answers
38
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
...
0
votes
1
answer
304
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....
1
vote
1
answer
152
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 ...
0
votes
1
answer
559
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....
0
votes
1
answer
324
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 ...
0
votes
1
answer
1k
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 ...
2
votes
1
answer
226
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 {
...
0
votes
1
answer
1k
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 ...
0
votes
1
answer
437
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 ...
-1
votes
1
answer
473
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 ...
0
votes
0
answers
1k
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 { (...
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 ...
2
votes
1
answer
719
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 ...
1
vote
1
answer
3k
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 ...
1
vote
2
answers
403
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)
...
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 ...
0
votes
1
answer
82
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 {
@...
6
votes
1
answer
2k
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 ...
0
votes
0
answers
17
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 ...
0
votes
1
answer
1k
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 ...
14
votes
2
answers
858
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 ...
5
votes
0
answers
189
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 ...
0
votes
0
answers
53
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 ...
-1
votes
1
answer
209
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 &...
2
votes
2
answers
2k
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 ...
1
vote
0
answers
65
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 ...
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 ...
0
votes
0
answers
90
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 ...
0
votes
2
answers
592
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 ...
7
votes
1
answer
1k
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 ...
0
votes
1
answer
322
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 ...
0
votes
1
answer
576
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 ...
1
vote
1
answer
170
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 ...
0
votes
1
answer
56
views
Simplifying REST API calls
I'm new to Java programming and I'm trying to reduce the number of REST API calls I make in my program to better organize it and I'm not sure how best to approach it if the simplest way is to have a ...
0
votes
1
answer
2k
views
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 ...
1
vote
2
answers
7k
views
System.TypeException: Mock object doesn't implement the supplied interface. Tried to add different methods in the mock class
I created a mock class which has different methods WHen I tried to get the different response based on my scenarios. Im getting the error like
'System.TypeException: Mock object doesn't implement ...
0
votes
1
answer
605
views
How to mock test a rest API implementation
I have a method
public static Map<String, Object> createNewAccessToken() {
Map<String, Object> access_token = null;
HttpRequest req = new HttpRequest();
req....
2
votes
1
answer
2k
views
System.XmlException: start tag unexpected character =
This is the full error:
System.XmlException: start tag unexpected character = (position: END_TAG seen ...<source> Bicycling</source><media:contenturl=... @1:688)
So from my ...
0
votes
0
answers
803
views
Mock HTTP Call Out In Test to Return XML
I am very new to HTTP Callouts and now I am in the testing phase. My HTTP Callout returns XML
This is the link. I input a company already, soulcycle, in case anybody wanted to see what was being ...
1
vote
1
answer
1k
views
Test error condition in finish() method of Batchable class
Trying to figure out how to test error condition in the finish() method of this Batchable class. I am testing the error condition in the execute() method by calling it separately in the test and ...