2

I have a process that acts on Contact creation and waits for an hour, then needs to check to see if a related object was created. Since I haven't found any way to check for that related object (because the lookup field is on that related object and pointing to the Contact), I was thinking that I could call an Apex class from the process builder.

So I'm wondering if the id of the current record that is going through the process is accessible from that called Apex class, so that I can check for the related object. Thanks!

  • Are you trying to find out if you can pass a parameter to an Apex Class from a PB? – Sebastian Kessel Jan 7 at 22:45
4

You can pass a list of ID's from process builder to the @InvocableMethod in Apex that represents the Contacts.

In Process Builder, you would set the Field that represents in method parameter to reference the Contact Id value.

Apex class

public class ContactInvokable {
    @InvocableMethod
    public static void ProcessContacts(List<Id> contactIds)
    {
        System.debug(contactIds);
    }
}

Immediate Action in Process Builder to call Apex class method enter image description here

Note how the field contactIds corresponds to the input parameter on the method.

Now if I edit an existing Contact after activating the process I get the following in the apex debug log:

enter image description here

  • 1
    note that AFAIK, the result from an invocable method can't be returned to PB for any use (which I suspect OP will need). Instead, the PB will need to use Flow that in turn uses invocable Apex to do something if one wants to process the result point-and-click: SFSE answer – cropredy Jan 8 at 0:26
  • 1
    @cropredy Fair point. I'd just assumed that once the processing was in Apex they could complete the required operations there rather than trying to get back into the process. – Daniel Ballinger Jan 8 at 0:29
  • @DanielBallinger is correct! That's all I really need, thank you so much for this answer! I was having trouble finding documentation on this so this helps significantly. – nicolevy Jan 8 at 14:16

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.