This interface allows an Adapter to be the source in a Pull Link, fetching records in batches from a source data store.

This is a very commonly-used interface; you will likely also want to consider implementing NamedCredentialAdapter and SchemaAdapter.


 * Implement this interface if your Adapter will be used in a Pull Model as a source of records. The most common
 * example of this is an Adapter that calls an external system to retrieve records.
global interface SourceAdapterForPull extends SourceAdapter {

     * This method helps you to scale seamlessly to fetch large numbers of records. We do this by splitting requests
     * out into separate execution contexts, if need be.
     * Valence will call planFetch() on your Adapter first, and then start calling fetchRecords(). The number of times
     * fetchRecords() is called depends on what you return from planFetch(). Every call to fetchRecords() will be in
     * its own execution context with a new instance of your Adapter, so you'll lose any state you have in your class.
     * @param context Information about this Link and the current execution of it.
     * @return
    FetchStrategy planFetch(LinkContext context);

     * Second, we will call this method sequentially with scopes you gave us in response to planPush(). We give you your
     * scope back so you can use it as needed.
     * If you need to mark errors as failed or warning, use the addError() and addWarning() methods on RecordInFlight.
     * @param context Information about this Link and the current execution of it.
     * @param scope A single scope instance from the List of scopes returned by planFetch()
     * @return All of the records that have been updated since the timestamp passed inside LinkContext.
    List<RecordInFlight> fetchRecords(LinkContext context, Object scope);


Records are retrieved in a two-step process:

1. Planning

First, there is a planning step. This allows Valence and your Adapter to negotiate the exchange of records that is about to happen. Valence gives you a preview of the request for information so that you can decide how to proceed.

This is used mostly to handle any pagination or batching that needs to take place in order to avoid limits (on either side of the information exchange).

The purpose of planning is to figure out if batches will be needed, how many batches would be needed, and what information is needed by each batch to do its job.

Valence will call planFetch() and hand your Adapter a LinkContext instance. Two values in particular are going to be important to you here:

  1. batchSizeLimit - the desired number of records returned by each call to fetchRecords().
  2. lastSuccessfulSync - a timestamp for the last time records were successfully retrieved from your adapter. Use this to estimate (or query and count) how many total records you expect to send to Salesforce.

Use these two values, plus what you know about the external system you are connecting to, to plan the retrieval of records.

Planning Result: a FetchStrategy

There are a number of strategies you can use to most effectively retrieve records from the system your adapter is talking to.

The return value for planFetch() lets Valence know how best to interact with your Adapter to get the records we’re interested in. You have tremendous flexibility and control over this process.


In between execution contexts your Adapter instance is destroyed and any state is lost. If you want to preserve any information (api tokens, offsets, etc), put it inside scope objects that you can give to Valence to hand back to you later.

2. Fetching

After planning is complete, it is time to retrieve records from the external system that your Adapter talks to.

Depending on the FetchStrategy that you returned from planFetch(), different things may happen here. Read up on the FetchStrategy class to understand your options. Also take a look at ChainFetchAdapter.

Your fetchRecords() method is invoked with two arguments:

  1. context - the LinkContext instance that contains general information you might need about the current sync that is in progress.
  2. scope - A scope object you gave Valence to give back to you later, or null, depending on the circumstances. Use these to craft a request to the external system. Perhaps you stored offsets in your scopes so that you could paginate a large result set.

To decide what you should be querying you can look at:

  1. context.linkSourceName - the name of the source table that should be queried (this will match one of the Table names your Adapter returned in getTables()).
  2. context.mappings - this is a List of mappings that hold the fields that should be queried from the source table. Records are given to Valence as RecordInFlight instances. The constructor for this DTO class expects a Map<String,Object> where the keys are the field names from the source system.


Each time fetchRecords() is invoked it is called on a new instance of your Adapter class that is inside its own execution context. This means you have a fresh set of Salesforce Governor Limits to work within. To see the limits, look at the asynchronous limits here: