Newer Version Available

This content describes an older version of this product. View Latest

Implementing the Process.Plugin Interface

Process.Plugin is a built-in interface that allows you to pass data between your organization and a specified flow.

The following are the methods that must be called by the class that implements the Process.Plugin interface:

Name Arguments Return Type Description
describe Process.PluginDescribeResult Returns a Process.PluginDescribeResult object that describes this method call.
invoke Process.PluginRequest Process.PluginResult Primary method that the system invokes when the class that implements the interface is instantiated.

Example Implementation

1global class flowChat implements Process.Plugin { 
2
3// The main method to be implemented. The Flow calls this at runtime.
4global Process.PluginResult invoke(Process.PluginRequest request) { 
5        // Get the subject of the Chatter post from the flow
6        String subject = (String) request.inputParameters.get('subject');
7        
8        // Use the Chatter APIs to post it to the current user's feed
9        FeedItem fItem = new FeedItem(); 
10        fItem.ParentId = UserInfo.getUserId(); 
11        fItem.Body = 'Force.com flow Update: ' + subject; 
12        insert fItem; 
13
14        // return to Flow
15        Map<String,Object> result = new Map<String,Object>(); 
16        return new Process.PluginResult(result); 
17    } 
18
19    // Returns the describe information for the interface
20    global Process.PluginDescribeResult describe() { 
21        Process.PluginDescribeResult result = new Process.PluginDescribeResult(); 
22        result.Name = "flowchatplugin";
23        result.Tag = "chat";
24        result.inputParameters = new 
25           List<Process.PluginDescribeResult.InputParameter>{ 
26               new Process.PluginDescribeResult.InputParameter('subject', 
27               Process.PluginDescribeResult.ParameterType.STRING, true) 
28            }; 
29        result.outputParameters = new 
30           List<Process.PluginDescribeResult.OutputParameter>{ }; 
31        return result; 
32    }
33}

Test Class

The following is a test class for the above class.

1@isTest
2private class flowChatTest {
3
4    static testmethod void flowChatTests() {
5      
6        flowChat plugin = new flowChat();
7        Map<String,Object> inputParams = new Map<String,Object>();
8
9        string feedSubject = 'Flow is alive';
10        InputParams.put('subject', feedSubject);
11
12        Process.PluginRequest request = new Process.PluginRequest(inputParams);           
13        
14        plugin.invoke(request);
15    } 
16}