TransformationFilter

This is the primary interface to implement if you are building a Filter. It will allow your Apex class to inspect records that are being processed, and modify them if need be.

Filters are given an opportunity to inspect and modify RecordInFlight instances during Link processing, after they are retrieved/handled by a Source Adapter but before they are delivered to a TargetAdapter.

Definition

/**
 * TransformationFilters are applied to RecordInFlight records.
 */
global interface TransformationFilter {

        /**
         * Given contextual information about a Link, let us know if this Filter is appropriate to use in this context. Perhaps your link only works
         * in certain scenarios, like when the local Salesforce org is the source system.
         *
         * If you're not sure what to do with this method, just return true.
         *
         * @param context Information about this Link execution in case you need it
         *
         * @return True if this Filter is appropriate to use with this Link
         */
        Boolean validFor(LinkContext context);

        /**
         * This method allows the Filter to inspect and possibly manipulate RecordInFlight records. These records represent a record that is
         * being processed inside of a Valence Link and is in the midst of syncing from a source system to a target system.
         *
         * Change records in the list, or the list itself, to affect what ends up in the target system. You can add/remove/change properties,
         * add errors or warnings to the record, or even remove it from the list entirely to drop it on the floor without causing a failed record.
         *
         * Word of warning: Do not add new records to the list. We've carefully calculated list size in order to not hit governor limits, and also
         * any new records are not going to be processed by filters that were applied before yours was.
         *
         * @param context Information about this Link execution in case you need it
         * @param records A subset (single batch) of records being processed by the Link
         */
        void process(LinkContext context, List<RecordInFlight> records);
}

Example Usage

global with sharing class ConstantFilter implements valence.TransformationFilter {

    public Boolean validFor(valence.LinkContext context) {
        // allow this filter to be used by any Link in any circumstance
        return true;
    }

    public void process(valence.LinkContext context, List<valence.RecordInFlight> records) {
        // add a constant property to every record that goes by
        for(valence.RecordInFlight record : records)
            record.getProperties().put('SpecialField', 'HelloThere');
    }
}