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;
pdf.setRedirect(true);
// 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();
efa.setFileName('Attachement');
efa.setBody(b);
// Sets the paramaters of the email
email.setSubject('Testing');
email.setToAddresses(mail);
email.setPlainTextBody('Test');
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); // Sends the email
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}