0

So, if I search for InvocableMethod there is a lot of documentation such as this:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm

And if I search for "pass record from Flow to Apex code" I see some examples like this:

https://www.crmscience.com/single-post/invoking-apex-with-flow-using-salesforce#:~:text=Invoke%20Apex%20From%20Flow.&text=After%20collecting%20the%20data%20or,parameters%20as%20variables%20you%20defined.

But I can't find a single example that shows sending the main record from Flow to Apex. But I think this would be common?

Assume I have a Flow that is triggered on create or update for an Opportunity. So the Opportunity should be $Record? Assume I have written an Apex class with an InvocableMethod. It is clear, from the documentation, how to call this Apex code from the Flow, but it is not clear how I would specify that I want to pass the Opportunity record to the InvocableMethod. Can someone explain what I need to specify in the Flow?

1 Answer 1

2

Invocable method will only accept these parameters as input as per the article.

There can be at most one input parameter and its data type must be one of the following:

  1. A list of a primitive data type or a list of lists of a primitive data type – the generic Object type isn’t supported.

  2. A list of an sObject type or a list of lists of an sObject type.

  3. A list of the generic sObject type (List) or a list of lists of the generic sObject type (List<List>).

  4. A list of a user-defined type, containing variables of the supported types or user-defined Apex types, with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure that your class contains at least one member variable with the invocable variable annotation.

In your scenario you can use List<Opportunity> as input parameter as below.

public class  senddatafromflowtoapex {
 @InvocableMethod (label = 'oppy flow' description = 'send oppy data to apex')
    
    public static void  senddata ( List<opportunity> opplist) {
        //logic here
    }
}

In the flow you can just give $Record as a parameter as shown below.

enter image description here

1
  • Thank you. This is great. Mar 16 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.