Unarchive SDK

Programmatically unarchive records in the Archive managed package based on specific filters and retrieve search results that match your request.

Note
Note This content relates to Archive. For Salesforce Archive, see Store Data Externally with Salesforce Archive.

Unarchiving a record also unarchives its entire hierarchical tree of root and child records.

Note
Note Unarchive isn't processed if the search result contains more than 1,000 records.
Note
Note

Unarchive requests via the Archive SDK are limited to 50 per hour per org.

If you exceed this limit, you receive HTTP status code 429.

Note
Note Unarchive SDK can run up to 10 unarchive actions simultaneously. Both Undo and SDK Unarchive are considered unarchive actions.

Prerequisites

Enable Archive Enable Unarchive to unarchive records from the Archive or via the Archive SDK. If you need only one unarchive permission, enable one of these custom permissions and manually assign it to a custom permission set or profile.

  • Archive Unarchive: Permission to unarchive records from the Archive only.
  • Archive Unarchive SDK: Permission to unarchive records via the Archive SDK only.

Unarchive SDK functions

Search one object per unarchive request and apply a maximum of six filters to the search.

performUnarchiveSdk(String sObjectName, List<SearchFilter> filters, DateRange dateRange)
performUnarchiveSdk(String sObjectName, List<SearchFilter> filters)

SDK parameters

sObjectName
The object queried by SDK. This parameter is required.
Search Filters
Filters that narrow search results based on field conditions. This parameter is required.
  • Field Name: The field to filter by, such as Name or CreatedDate.
  • Value or List of Values: The specific value or values to match. If you use a list of values, SDK Data Queries combines them with an OR operator.
Date Filters
To search based on dates, use the DateRange parameter and the required filters. DateRange filters records by fields such as ArchiveDate, CreatedDate, and ModifiedDate. This parameter is optional. Date filter recommendations:
  • Add the archive_date date field to search based on the archive date.
  • Use the SDK date format: MM/DD/YYYY.

Returned values

The return value is ArchiverAccessorResponse.

  • Request ID of the unarchive operation performed
  • Total number of records retrieved by the search
  • Status code, including errors
ArchiverAccessorResponse.getBody(); ⇒ String
ArchiverAccessorResponse.getStatusCode(); ⇒ String
  200 - if we accepted your request
  400 - if we did not accept your request
ArchiverAccessorResponse.getErrorMessage(); ⇒ String

Unarchive SDK scenarios

Review examples of the unarchive SDK process in the Archive managed package.

Scenario 1: Fewer than 1,000 matching records found, request processed—Success!

A customer wants to unarchive all candidates who have a bachelor's degree.

  • The customer executes the Archive SDK Unarchive function with the filter has BA=true.
  • The system searches the candidate list and finds fewer than 1,000 archived records.
  • A new activity of type Archive SDK Unarchive is added, and all unarchive fields are completed. The return value is the number of records found.

Scenario 2: More than 1,000 matching records found, request not processed—Failure

A customer wants to unarchive all candidates who have a master's degree.

  • The customer executes the Archive SDK Unarchive function with the filter has MA=true.
  • The system searches the candidate list and finds more than 1,000 archived records.
  • The Archive SDK unarchive process ends unsuccessfully, and no activity is created. The return value includes the number of records found and an error: 400, scope too large.

Scenario 3: Fewer than 1,000 records, no matching records found, no request processed—Failure

A customer wants to unarchive all candidates who have a master's degree.

  • The customer executes the Archive SDK Unarchive function with the filter has MA=true.
  • The system searches the candidate list and finds fewer than 1,000 records, but no matching records are found. No activity is created. The return value is the number of records found.

Scenario 4: Fewer than 1,000 matching records found, request processed, partial success—Success!

A customer wants to unarchive all candidates who have a bachelor's degree.

  • The customer executes the Archive SDK Unarchive function with the filter has BA=true.
  • The system searches the candidate list, finds fewer than 1,000 records, and unarchives them.
  • Records that match the filter unarchive successfully. A new activity of type Unarchive-SDK is added, and all unarchive fields are completed. The return value is the number of records found.

Code Documentation

performUnarchiveSdk(String sObjectName, List<SearchFilter> filters, DateRange dateRange)
performUnarchiveSdk(String sObjectName, List<SearchFilter> filters)

Return Value: ArchiverAccessorResponse

ArchiverAccessorResponse.getBody(); ⇒ String
ArchiverAccessorResponse.getStatusCode(); ⇒ String
  200 - if we accepted your request
  400 - if we did not accept your request
ArchiverAccessorResponse.getErrorMessage(); ⇒ String

Code Examples

Example 1: Unarchive Accounts named Own.

List<SearchFilter> request = new List<SearchFilter>();
String objectName = 'Account';
SearchFilter filter1 = new SearchFilter('Name', 'Own');
request.add(filter1);
ArchiverAccessorResponse res = ArchiverAccessor.performUnarchiveSdk(objectName, request);
Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());

system.debug(jsonMap.get('request_id'));
system.debug(jsonMap.get('total_result_count'));

Example 2: Unarchive Accounts with a filter, where name is PersonAccount3 and the date range is records created in the last 150 days.

// Initialize a list to hold search filters for the archive operation
List<OB_Archiver.SearchFilter> request = new List<OB_Archiver.SearchFilter>();

// Define the Salesforce object name to perform the operation on
String objectName = 'Account';

// Create a search filter based on the 'Name' field with a specific value
OB_Archiver.SearchFilter filter1 = new OB_Archiver.SearchFilter('Name', 'PersonAccount3');

// Add the created filter to the request list
request.add(filter1);

// Create a date range filter to select records created in the last 150 days
// It calculates the start date by subtracting 150 days from today's date
OB_Archiver.DateRange range = new OB_Archiver.dateRange('CreatedDate', system.today()-150, system.today());

// Perform the unarchive operation with the specified object name, filters, and date range
// This retrieves records from the archival that match the given criteria
OB_Archiver.ArchiverAccessorResponse res = OB_Archiver.ArchiverAccessor.performUnarchiveSdk(objectName, request, range);

// Deserialize the JSON response body to a Map object to easily access the data
Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());

// Debug print the request ID and total result count from the response for logging purposes
system.debug(jsonMap.get('request_id'));
system.debug(jsonMap.get('total_result_count'));

Unarchive SDK Scenarios

Examples of the unarchive SDK process in the Archive managed package.

Scenario #1: Less than 1000, records found request processed—Success!

  1. According to a new business request, a customer would like to unarchive all candidates who have a Bachelor Degree.
  2. Use the Archive SDK Unarchive function, with filter (e.g.: has BA=true).
  3. The candidate list found is less than 1000, and the records are unarchived.
  4. A new activity is added, with a new typeArchive SDK Unarchive function, with all the unarchive fields filled out.
  5. The Unarchive-SDK ends successfully.

    Return value = The number of records found

Scenario #2: More than 1000, records found, request not processed—Failure

  1. According to a new business request, the customer would like to unarchive all candidates who have a Master Degree.
  2. Use the Archive SDK Unarchive function with filter. For example,MA=true.
  3. The candidate list found, is more than 1000, and the records aren't unarchived.
  4. The Archive SDK Unarchive ends unsuccessfully.
    No activity is created.
    Return value =# records found, error: 400, scope too large

Scenario #3: Less than 1000, no records found, no request processed—Failure

  1. According to a new business request, the customer would like to unarchive all candidates who have a Master Degree.
  2. Use the Archive SDK Unarchive function, with filter (for example:has MA=true).
  3. The candidate list found, is less than 1000, and no records found according to the criteria.
    No activity is created added.
    Return value = # records found

Scenario #4: Less than 1000, records found, request processed, partial success—Success!

  1. According to a new business request, the customer would like to unarchive all candidates who have a Bachelor Degree.
  2. Use the Archive SDK Unarchive function, with filter (for example: has BA=true).
  3. The candidate list found, is less than 1000, and the records are unarchived.
  4. Some of the records unarchive successfully and some not.
    A new activity is added, with a new type “Unarchive-SDK” with all the unarchive fields filled out.
  5. The Archive SDK Unarchive ends successfully.
    Return value = # records found