[SalesForce] In Process Builder, can’t pass reference to process’s object to Apex using InvocableMethod

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:

enter image description here

Only 1 "Type" is available (Reference), and when I click in the "Value" box I get this:

enter image description here

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:

enter image description here

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:

enter image description here

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 generic sObject itself) should be supported.


I modified the invocableMatchLead method to take a collection of Lead sObjects directly.

@InvocableMethod
public static void invocableMatchLead(List<Lead> leads) {
    List<Lead> theLeads = new List<Lead>();
    for (Lead l : leads) {
        // Do Something
        //l.Comments__c = 'changed';
    }
}

I was then able to configure calling this method from a scheduled action. enter image description here

Related Topic