I have a process builder which invokes the Apex class. This Apex sends out an email to the Contact. The attachment of the Email is a VF page which gets the list of line items.

The issue here is that I would like to capture the record id of the record invoked by Process Builder and pass it on all the way to the VF page.

Any sample code or ideas would greatly help

 public SendEmailInvoice()


    public class MyInvocableVariable {
    @InvocableVariable(label='Id' required=true)
    public Id recId;

   @InvocableMethod(label='Send an email from apex class'
 description='sends an email')

    public static void send()

        List<MyInvocableVariable> myInvocableVariableList = new List<MyInvocableVariable>();
 for(MyInvocableVariable myInvocableVariable : myInvocableVariableList) {

       system.debug('recId=' + myInvocableVariable.recId);
                 // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        PageReference pdf = Page.SendInv;


        // Take the PDF content
        Blob b = pdf.getContent();
 List<String> mail = new List<String>();
        mail.add('[email protected]');
        // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();

        // Sets the paramaters of the email


        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); // Sends the email

        Messaging.SendEmailResult [] r =

            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  

  • Where are you encountering difficulty? Your Invocable Apex presumably has the id of a record already, and must be passing some kind of identifier to the Visualforce page.
    – David Reed
    Mar 26, 2018 at 17:16

2 Answers 2


Don't get confused.. as glls said, it's pretty straightforward...all you need it a recId.

public static void send(List<Id> ids).. 

create a List argument in the function to get the recIds.. then to You process builder and assign the ID to recordId or Id You want to set... where You are calling this function.

You can see, I have a process builder on Account, an action that always run. and not I am getting the method agreement i.e ids with the AccountId..

enter image description here

  • Got it. That worked perfect
    – user43146
    Mar 26, 2018 at 20:04

This is all covered in the documentation and Trailhead(s)

Automate Basic Business Processes with Process Builder

You will find that by Annotating your method with @InvocableMethod, this can easily be achieved:


    public class AccountQueryAction {
    @InvocableMethod(label='Get Account Names' description='Returns the list of account names corresponding to the specified account IDs.')
    public static List<String> getAccountNames(List<ID> ids) {
        List<String> accountNames = new List<String>();
        List<Account> accounts = [SELECT Name FROM Account WHERE Id in :ids];
        for (Account account : accounts) {
        return accountNames;

and you can invoke your method from the process builder.

  • I did try that. Just updated the code that I tried. I am getting the Id as null here, so I am unable to pass it to the VF page
    – user43146
    Mar 26, 2018 at 18:19
  • the documentation is very straightforward on this topic. If you are running into any issues, open a new post alongside your code, process builder images and any error messages so we can assist. Thanks
    – glls
    Mar 26, 2018 at 18:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .