Connections Element

Last, but not least, in the Manager tab of the strategy, you can setup a new connection. A connection is again implemented by an Apex class and allows you to enhance the strategy with additional information being returned from your Apex class. The Apex class can optionally be supplied with input parameters and will return one or more output parameters. An example of this could be calling out to an external weather service. You supply the address of the account that is related to the case as input parameters and return the temperature and windspeed back to strategy. That temperature and windspeed can then be used in the strategy in Filters, Branch Selectors, etc.

The Apex for this looks like:

global class NBAConnectionTemplate {

    @InvocableMethod(
        label='NBA Connection Example'
        description='This function simulates an external weather service')
        global static List<NBAConnectionTemplateResult> sampleMethod(List<NBAConnectionTemplateRequest> inputRequests) {
            List<NBAConnectionTemplateResult> outputs = new List<NBAConnectionTemplateResult>();
            
            for (NBAConnectionTemplateRequest singleRequest : inputRequests)
            {
                NBAConnectionTemplateResult output = new NBAConnectionTemplateResult();
                
                //Normally you would callout to a real weather service here, for now we'll fake it.
                if (singleRequest.City == 'Oslo' && singleRequest.Country == 'Norway')
                {
                    output.Temperature = 10;
                    output.Windspeed = 2;
                }
                else
                {
                    output.Temperature = 25;
                    output.Windspeed = 5;
                }
                outputs.add(output);
            }
            return outputs;
        }
    
    
     global class NBAConnectionTemplateRequest {
        @InvocableVariable
        global String City;
         
        @InvocableVariable
        global String Country;
    }
    
    global class NBAConnectionTemplateResult {
        @InvocableVariable
        global Integer Temperature;
        
        @invocableVariable
        global Integer Windspeed;
    }
}

Note:
• This time we created two internal classes, one for the inputs and one for the outputs.

Next, we can setup the Connection in the strategy:

Connection Screenshot

You need to realize that the connection function is executed when the Strategy is started. This means that for the input parameters you can use information from the global variables, like the $Record and $User but not any information coming from Recommendations because those are not loaded yet. In this case we supply the BillingCity and BillingAccount of the Account related to the Case to the service.

Having named the Connection ‘ExternalWeatherService’ when creating it in the Strategy, we can then refer to it through $ExternalWeatherService when setting up our Branch Selector:

Connection Screenshot

So now when the temperature is 15 or below, Recommendation 1 is shown and otherwise Recommendation 2 is shown.

Back to Elements

1831 reads