function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BenjaminBBenjaminB 

Flow Apex plug-in for Approval Request

Hi guys,

 

I'm struggling with developing a plug-in for Visual Workflow to make it possible to submit a record for approval.

I want the plug-in to work with a mandatory RecordID and optional comment. Right now I've got the following code:

public class FlowApprovalSubmit{
// This method describes this plugin, as well as its inputs and outputs to the Cloud Designer
// NOTE: Implementing this method is what makes this class appear in the designer
global Process.PluginDescribeResult describe() {
    // Set up plugin metadata
    Process.PluginDescribeResult result = new Process.PluginDescribeResult();
    result.description = 'The FlowApprovalSubmit Flow Plug-in submits a requested record for approval';
    result.tag = 'Approval Handling';
 
    // create a list that stores both mandatory and optional *input* parameters from a Flow
    // NOTE: Only primitive types (STRING, NUMBER, etc) are supported at this time.
	// Collections are not currently supported
    result.inputParameters = new List<Process.PluginDescribeResult.InputParameter>{
        // Record ID (mandatory)
        new Process.PluginDescribeResult.InputParameter('RecordID',
                Process.PluginDescribeResult.ParameterType.STRING, true),
        // Comments (optional)
        new Process.PluginDescribeResult.InputParameter('ApprovalComments',
                Process.PluginDescribeResult.ParameterType.STRING, false),
    };
 
    // Create a list that stores *output* parameters sent *to* your flow.
    result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter>{
        // Account ID of the converted lead
        new Process.PluginDescribeResult.OutputParameter('getComments',
                Process.PluginDescribeResult.ParameterType.STRING),
        //...
    };
 
    return result;
};

global Process.PluginResult invoke(Process.PluginRequest request) {
    String RecordID = (String) request.inputParameters.get('RecordID');
    String ApprovalComments = (String) request.inputParamaters.get('ApprovalComments')
	
		Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
			req1.setComments(ApprovalComments);
			req1.setObjectId(RecordID);
		Approval.ProcessResult result = Approval.process(req1);
	
    return new Process.PluginResult(result);
}

}

 

 The problem that it returns is on line 20 where it doesn't expect the "}"

 

Could someone please tell my why and how I can solve it? Also, I would be very thankful if someone reviewed the code and gave me pointers.

 

Thank you so much!

Best Answer chosen by Admin (Salesforce Developers) 
BenjaminBBenjaminB

I gues using the developer console isn't for me...

 

I used the ant to upload this: https://github.com/raja-sfdc/FlowPluginPack


It worked perfectly!