LinkSplitFilter

This interface allows a Filter to be part of the logic flow of one or more Link Splits.

LinkSplitFilters are not extensions of TransformationFilter and are not expected to mutate RecordInFlight instances.

Instead, their job is to evaluate each RecordInFlight and decide if it should, or should not, be sent to a given Link Split child of a running Link. They are, in some ways, a router directing traffic.

Definition

/**
 * A Filter that is used to evaluate RecordInFlight instances to see if they should be processed by a Link Split.
 */
global interface LinkSplitFilter {

        /**
         * Consider a List of RecordInFlight instances against the LinkContext they would be run against if they were allowed to proceed.
         *
         * @param context Details about the Link that would run if some records are accepted
         * @param records The records to evaluate
         *
         * @return An ordered list of true/false, where each item is the acceptance/rejection of the corresponding index in the records parameter
         */
        List<Boolean> evaluate(LinkContext context, List<RecordInFlight> records);
}

Example

Let’s say you have a Link called “AllRecords”, whose job it is to pick up any records that have changed in a remote database regardless of the table they come from.

You are expecting three flavors of records:

  1. Companies (which you want to put in Account)
  2. People (which you want to put in Contact)
  3. Invoices (which you want to put in Invoice__c)

Consequently, you have three additional Links (one for each of these types of records).

AllRecords runs, and it has 20 records that are a mix of all three types. How do you decide what to do next? That’s where LinkSplitFilter comes in.

If the User selects a LinkSplitFilter when they are setting up the three Link Splits (one for each of our data types) that Filter will get a chance to give a thumbs up or down on each record.

The evaluate() method will be invoked three times, with a different LinkContext each time (corresponding to each of our child Links). The logic below would sort records appropriately.

public List<Boolean> evaluate(valence.LinkContext context, List<valence.RecordInFlight> records) {

            List<Boolean> results = new List<Boolean>();

    for(valence.RecordInFlight record : records) {

                    // let's say that the AllRecords Link adds a field to each record called "dataType" that holds a string value indicating what flavor of record it is
                    String dataType = (String)record.getOriginalPropertyValue('dataType');

                    switch on dataType {
                            when 'company' {
                                    results.add('Account'.equalsIgnoreCase(context.linkTargetName));
                            }
                            when 'person' {
                                    results.add('Contact'.equalsIgnoreCase(context.linkTargetName));
                            }
                            when 'invoice' {
                                    results.add('Invoice__c'.equalsIgnoreCase(context.linkTargetName));
                            }
                    }
            }

            return results;
}