Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Adding Query Pagination Support

DevKit is compatible only with Studio 6 and Mule 3. To build Mule 4 connectors, see the Mule SDK documentation.

Query Pagination comes as a need when dealing with a high quantity of records. The main advantage is performance as Mule runtime partially processes chunks of records at a time instead of trying to process all the records in memory at the same time.

To implement pagination in your connector, ensure that the service’s API to which you want to connect provides pagination functionality.
Be aware that enabling pagination on your connector may break backward compatibility with older Mule versions (prior to Mule Runtime 3.5.x) as it might change the returned type of a processor.

Enabling Pagination

Enabling pagination in your connector is fairly straightforward. There are only three required conditions that your @Processor method must meet:

  1. Annotate the method with @Paged

  2. Must receive a parameter with type org.mule.api.streaming.PagingConfiguration

  3. The return type must be a ProviderAwarePagingDelegate

@Paged
@Processor
    public ProviderAwarePagingDelegate query(String query, final PagingConfiguration pagingConfiguration) throws Exception
{
    return new CustomPagingDelegate(query,pagingConfiguration);
}

public QueryResult executeQuery(String query, String nextItem) throws Exception {
        myServiceClient.query(query,nextItem);
}
java

Note: The difference between the @Processor method and the operation executeQuery. The processor returns a PagingDelegate that later on (when retrieving a page) receives a connector instance already connected and executes executeQuery accordingly.

Creating a CustomPagingDelegate

The ProviderAwarePagingDelegate is where the pagination happens. Take a look at the ProviderAwarePagingDelegate abstract class, which requires two type arguments (T and P in this case). In the class definition below, T represents the data to be returned and P represents the provider of the data, your Anypoint Connector.

Note again that when executing the methods getPage(P provider) and getTotalResults(P provider), Anypoint Connector DevKit picks the correct instance of your connector out of the connection pool.

To create your own version of ProviderAwarePagingDelegate, you must extend it. Below is an example of a simple extension of this class:

See Also