Hi so I'm trying to make a test class for my http callouts class. Now the problem is that I understand that I cannot make multiple DML and HTTP callouts in a single transaction but the third party API that I'm using is paged. Now my logic depends on making multiple callouts in a single transaction and I also cannot use that suggested list approach and delay the DML operaitons. So I have to enter data in two custom objects and adding the data in the second custom object is dependent on the DML operations obtained from the first HTTP callout. What do I do. It is really frustrating how things are so restricted with Salesforce.

  • 1
    Without seeing your code, there's not much we can do to help you find out what you can do. At minimum, we would like to see a sscce so that we can further assist you. I assure you, there's almost certainly a way to success, but without a detailed situation, we'd be forced to fill in a lot of the blanks. Please edit your question with some code so we can better assist you.
    – sfdcfox
    Oct 8, 2018 at 22:15
  • The sample code in Testing Apex Callouts using HttpCalloutMock has an example on "Testing multiple HTTP callouts". Mixing in intermediate DML operations is a separate consideration. You might need to isolate the testing of the parts involved here. Test or not, you can't have DML proceeding callouts. Except for you do the required setup DML before calling Test.startTest() Oct 9, 2018 at 0:19

2 Answers 2


You can have more than one callout in a test class. Check the Salesforce developer blogs for examples. This one looks like what you need.


Copying code here for your convenience

private class ProcessAccountsContactsTest {
@isTest static void testCallout() {
    MultiStaticResourceCalloutMock multimock = new MultiStaticResourceCalloutMock();
    // 3 test accounts
    // 3 test contacts
    multimock.setHeader('Content-Type', 'application/json');

    // Set the mock callout mode
    Test.setMock(HttpCalloutMock.class, multimock);

    // Call the method that performs the callouts
    Integer result = ProcessAccountsContacts.processAccountsContacts();

    // Verify response is as expected, given the test data
    System.assertEquals(6, result);

Here is a previous answer I gave which will allow you to specify which response to return either based on endpoint or content (useful if the endpoint does not change but the content of the request does. Like a filter on a work for example).

It’s the simplest way to do it. Your test method defines the response and when it is used. Does not mandate static resources and your tests have full control. The echo class can be used throughout your codebase without having to code specific responses in the echo class.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.