ArchiverAccessor Class

Provides access to Archive Apex. In tests, use setMock() to return a simulated response instead of making a live archive callout.

Namespace

SF_Archive

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.

1// MockHttpResponseGenerator.cls
2@IsTest
3public class MockHttpResponseGenerator implements HttpCalloutMock {
4    public String fakeResponseJson;
5    public Integer statusCode;
6    String redirectHeader;
7
8    public MockHttpResponseGenerator(String fakeResponseJson, Integer statusCode) {
9        this.statusCode = statusCode;
10        this.fakeResponseJson = fakeResponseJson;
11        this.redirectHeader = '/example/test';
12    }
13
14    public HttpResponse respond(HttpRequest req) {
15        HttpResponse res = new HttpResponse();
16        res.setBody(this.fakeResponseJson);
17        res.setStatusCode(this.statusCode);
18        res.setHeader('Location', this.redirectHeader);
19        return res;
20    }
21}
22// SearchSdkTest.cls
23@IsTest
24public with sharing class SearchSdkTest {
25    @IsTest
26    private static void searchSdk() {
27        String jsonBody = '{"records":[{"CaseNumber":"01916767","Id":"500Xx000000XXXXXX"}],"total_result_count":1,"scroll_id":"-1"}';
28
29        SF_Archive.ArchiverAccessor.setMock(new MockHttpResponseGenerator(
30            jsonBody, SF_Archive.ArchiverAccessorResponse.HTTP_200_OK));
31
32        List<SF_Archive.SearchFilter> filters = new List<SF_Archive.SearchFilter>{
33            new SF_Archive.SearchFilter('Name', 'test')
34        };
35
36        Test.startTest();
37        SF_Archive.ArchiverAccessorResponse res =
38            SF_Archive.ArchiverAccessor.performArchiverGlobalSearch('Account', filters);
39        Test.stopTest();
40
41        Assert.areEqual(SF_Archive.ArchiverAccessorResponse.HTTP_200_OK, res.getStatusCode());
42        Assert.areEqual(jsonBody, res.getBody());
43    }
44}