This is driving me crazy because I JUST did this a month ago.
I have a simple apex class that exposes an invocable method so that I can call it from process builder:
public with sharing class SuperSimpleInvocable {
/**
* Inner class used to wrap a Lead object so that it can be invoked through Process Builder
*/
public class InvocableVariableLead {
@InvocableVariable(label='Lead' required=true)
public Lead theLead;
}
/**
* InvocableMethod implementation that can be invoked through Process Builder
*/
@InvocableMethod
public static void invocableMatchLead(List<InvocableVariableLead> leads) {
List<Lead> theLeads = new List<Lead>();
for (InvocableVariableLead ivl : leads) {
ivl.theLead.Comments__c = 'changed';
}
}
}
The problem is that when I create a process on the Lead object in Process Builder, when I attempt to call this class I'm not given the option to pass the Lead that's being acted upon. Here's what I'm getting:
Only 1 "Type" is available (Reference), and when I click in the "Value" box I get this:
As I said, I JUST did this with another process/apex class a month ago and I was able to get [Lead] in there. I even still have the process – the apex call looks like this:
Did something change? Am I missing something?
UPDATE:
I figured out a workaround for this scenario, however I'm still frustrated that things are working differently.
I changed my class to this:
public with sharing class SuperSimpleInvocable {
@InvocableMethod
public static void invocableMatchLead(List<Id> leadIds) {
List<Lead> theLeads = [select Comments__c from Lead where Id in :leadIds];
for (Lead l : theLeads) {
l.Comments__c = 'changed';
}
update theLeads;
}
}
And then my process invoked it with the following settings:
Best Answer
Do you actually need the
InvocableVariableLead
inner class with the@InvocableVariable
annotated member? According to InvocableMethod Annotation a list of any sObject type (except the genericsObject
itself) should be supported.I modified the invocableMatchLead method to take a collection of Lead sObjects directly.
I was then able to configure calling this method from a scheduled action.