Provides access to Archive Apex. In tests, use setMock() to return a simulated response instead of making a live archive callout.
Namespace
Usage
In an Apex test, call setMock() to register a mock response so your test doesn't make a live callout to archived data.
ArchiverAccessor Methods
The following are methods for ArchiverAccessor.
setMock(mock)
Instructs the Apex runtime to send a mock response whenever Archive Apex makes a callout, so you can test your Apex without accessing archived data.
Signature
public static void setMock(System.HttpCalloutMock mock)
Parameters
- mock
- Type: System.HttpCalloutMock
- The mock implementation that returns your simulated response.
Return Value
Type: Void
Example
This example tests global search against archived data. MockHttpResponseGenerator implements HttpCalloutMock and returns a simulated response, so the test runs without a live archive callout.
// MockHttpResponseGenerator.cls @IsTest public class MockHttpResponseGenerator implements HttpCalloutMock { public String fakeResponseJson; public Integer statusCode; String redirectHeader; public MockHttpResponseGenerator(String fakeResponseJson, Integer statusCode) { this.statusCode = statusCode; this.fakeResponseJson = fakeResponseJson; this.redirectHeader = '/example/test'; } public HttpResponse respond(HttpRequest req) { HttpResponse res = new HttpResponse(); res.setBody(this.fakeResponseJson); res.setStatusCode(this.statusCode); res.setHeader('Location', this.redirectHeader); return res; } } // SearchSdkTest.cls @IsTest public with sharing class SearchSdkTest { @IsTest private static void searchSdk() { String jsonBody = '{"records":[{"CaseNumber":"01916767","Id":"500Xx000000XXXXXX"}],"total_result_count":1,"scroll_id":"-1"}'; SF_Archive.ArchiverAccessor.setMock(new MockHttpResponseGenerator( jsonBody, SF_Archive.ArchiverAccessorResponse.HTTP_200_OK)); List<SF_Archive.SearchFilter> filters = new List<SF_Archive.SearchFilter>{ new SF_Archive.SearchFilter('Name', 'test') }; Test.startTest(); SF_Archive.ArchiverAccessorResponse res = SF_Archive.ArchiverAccessor.performArchiverGlobalSearch('Account', filters); Test.stopTest(); Assert.areEqual(SF_Archive.ArchiverAccessorResponse.HTTP_200_OK, res.getStatusCode()); Assert.areEqual(jsonBody, res.getBody()); } }