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
Andrey BolkonskyAndrey Bolkonsky 

How to call my Apex Method from a Flow

Hello,

I just finished my first ever Apex class (I am very new to this stuff). The main method I want to call has the return type of string. 

I want to write a trigger and also a flow to call it just so I know how to use both to trigger Apex. But When I try to use the @InvocableMethod anotation so I can launch it from a flow, I get the error

InvocableMethod methods do not support return type of String

Below is the firtst part of the method I want to call.
 
@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
            public static String writeNumber()

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Andrey,

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

As mentioned in the above documentation can you check if you are able to return list<string>.
 
Inputs and Outputs

There can be at most one input parameter and its data type must be one of the following:
>>A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
>>A list of an sObject type or a list of lists of an sObject type.
>>A list of the generic sObject type (List<sObject>) or a list of lists of the generic sObject type (List<List<sObject>>).
>>A list of a user-defined type, containing variables of the supported types above 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.

If the return type is not Null, the data type returned by the method must be one of the following:
>>A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
>>A list of an sObject type or a list of lists of an sObject type.
>>A list of the generic sObject type (List<sObject>) or a list of lists of the generic sObject type (List<List<sObject>>).
>>A list of a user-defined type, containing variables of the supported types above 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.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Andrey BolkonskyAndrey Bolkonsky
I have tried to convert it, but it wont allow me to have a Integer as a paramter. I am getting the exception:

Unsupported parameter type Integer. Valid invocable parameters must be List types like List<T> where T is a supported type
 
@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
            public static List<String> writeNumber(Integer Amt) {
                List<String> spelledAmount=new List<String>();
                Integer Amount=Amt;
                Integer Len;

//Code

    return spelledAmount;