I have a flow where I'm populating a Lead record variable with some field values
I want to pass this variable to an apex @InvocableMethod, so that apex can upsert the lead, and do some other logic.
My apex method looks like this
@InvocableMethod(label='Upsert Lead')
public static List<String> upsertLead(List<Lead> leads ){
Then in the flow, I assign the newLead variable to the upsertLead invocable method
However, when I run the flow, I receive the following error:
Apex_Upsert_Lead Inputs: leads = {!newLead} (Lead (No ID)) Error Occurred: An Apex error occurred: System.UnexpectedException: Illegal arguments
As per the docs here https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm I should be able to pass a specific-sobject type to the invocable method.
Also, note that the argument on the method is a list, but the variable in the flow is a single record lead variable. This is expected (I believe), simply because the Invocable interface is bulkified.
If the data types were not compatible the flow wouldn't let me assign that variable to the input of the method.
Thoughts on what I'm doing wrong?