Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 46017

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

3 votes

Can a Test Class have no member variables?

Each test method in a test class is executed in a separate transaction. Although you'd be able to "see" a static variable in each test method in the sense that it would be defined, it'd always be null …
David Reed's user avatar
  • 93.7k
2 votes
Accepted

Can I query custom metadata type record in a HttpCalloutMock?

Yes, you can. Custom Metadata is considered, well, metadata, and it's available to query in an Apex unit test (unlike Custom Settings). It's important to bear in mind that this creates an external de …
David Reed's user avatar
  • 93.7k
3 votes

Test class get error System.CalloutException: You have uncommitted work pending. Please comm...

Your class makes a callout after you perform DML. From Salesforce knowledge base: You can't make callouts, HTTP or otherwise, once you have made changes to the database. It's true that you cannot …
David Reed's user avatar
  • 93.7k
0 votes

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

but the concern is with the connected app we can integrate with two orgs This is not accurate. When you perform an OAuth connection to a Salesforce org, you supply a Connected App to define who you …
David Reed's user avatar
  • 93.7k
1 vote
Accepted

Test error condition in batch class with callouts

This is a tricky subtlety that has to do with how asynchronous Apex is enqueued and executed in unit test context. I think your code probably works, but in the way you're testing it right now, you can …
David Reed's user avatar
  • 93.7k
1 vote
Accepted

How to fix Attempt to de-reference a null object in test for Post Callout?

This is pretty straightforward. Your code is designed to return a null value given an invalid response, and that's exactly what it's doing. Your test does this: Test.setMock(HttpCalloutMock.class, n …
David Reed's user avatar
  • 93.7k
2 votes
Accepted

Test failure 7% for HTTP Call out

Your mock appears to me to be correctly implemented, at a glance. The issue is that your assertion is failing, and it's failing for a pretty comprehensible reason. In your class that performs the cal …
David Reed's user avatar
  • 93.7k
2 votes
Accepted

Test Class for the Apex Callout with OAuth

Mocks do not replace the need to create and insert appropriate test data to ensure your code executes the logic path you are aiming to test. Here, your unit test code must create and insert a ExtCre …
David Reed's user avatar
  • 93.7k
4 votes
Accepted

Is Test.isRunningTest() needed to prohibit an apex test from performing a callout even if yo...

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 test run? You do not need to change your code unde …
David Reed's user avatar
  • 93.7k
18 votes
Accepted

How do I unit test code that includes a callout?

Salesforce makes available two Mock interfaces (HttpCalloutMock, for REST calls, and WebServiceMock, for SOAP calls), as well as the StaticResourceCalloutMock and MultiStaticResourceCalloutMock implementations … these Trailhead modules: Apex REST Callouts Apex SOAP Callouts For more in-depth information, explore these sections in the Apex Developer Guide: Testing HTTP Callouts Test Web Service Callouts HttpCalloutMock
14 votes
Accepted

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

Yes, you can, using either of two techniques. Your HttpCalloutMock's respond() method can inspect its inbound HttpRequest, and construct a different response based on which endpoint is being called, t …
David Reed's user avatar
  • 93.7k