I am working with a supplier who proscribes DML operations on its application's objects. Instead, they ask us to call Rest resources in our org that they developed in order to interact with the data. I have developed a batch apex class which acts as a middle-ware component to pull data from an external system does some manipulations and then calls the rest resource the supplier created to push data. See below psuedo code:

global class BatchJob implements Database.Batchable<sObject>, Database.AllowsCallouts{
String query;
String Endpoint = 'https://api.*******';
private String API_Key;
private date cutOffDate= Date.newInstance(2001,01,01);

global Database.QueryLocator start(Database.BatchableContext bc){    
    query = 'Select Employee__ExternalId__c from Employee__c where Employee__EndDate__c != null';
    return Database.getQueryLocator(query);

global void execute(Database.BatchableContext BC, List<Employee__c> scope){
      /* 1. Call external API to get the required Data
         2. With the data returned from above api call, do some stuff 
            and then generate as json and post it to the supplier's rest resource */

global void finish(Database.BatchableContext BC){
    //Send Email

Coming to my question, for my test class now I need to insert into Employee__c but I would need to call the rest resource(another one not in the above code) of the supplier to insert into Employee__c. Would the employee insertion be rolled back?

1 Answer 1


In test class all api calls are dummy, means that you don't actually make api calls in test class, instead you create a class which implements HttpCalloutMock. It provides you the appropriate response in your test class.

Check this documentation for further information.

So this way it will not actually change anything on external system. So that no Rollback is required.

  • Sorry maybe I wasn't clear enough, I know about the mock call out class, however in this instance I want to actually call a rest resource in my test class to insert test data into employee__c object. Is that even possible?
    – SFDC_Dev
    Sep 11, 2018 at 10:37
  • Perhaps you did answer my question "In test class all api calls are dummy, means that you don't actually make api calls in test class". Sorry I was being daft I guess!
    – SFDC_Dev
    Sep 11, 2018 at 10:39
  • Yes you can't make any type of actual api calls through test class. It is not possible.
    – Mr.Frodo
    Sep 11, 2018 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .