+ Start a Discussion
Snita LalSnita Lal 

Need store/access variables in invocable method that calls a future class. Is Invocable method handler the solution?

Fairly new to apex and we are trying to build a mechanism for sending a VF page to specific users that are defined as lookups on the custom object that sends the email.

We have managed to get an invocable method which calls an @future class which builds the attachment from the VF and sends the emai. The reason we have this seperately is the @future allows for the record to be updated and a populated VF page be posted to the email as an attachment.

We start to hit issues when we look to add more variables in the Invocable Method, other than the ID. Specifically trying to access the email address of the users added to the lookups on the record. At the moment the class sends to a static address for testing purpose. Appreciate the documentation for invocable methods highlights this fact.

We have seen examples of Invocable Method Handlers used in combination with an Invocable Method to collect additional variables, however we're unsure how this would work when the invocable method, calls a future class which does all the work. Unsure of how to structure this and any guidance or advice would be gratefully appreciated.

Current code posted below.
public class MakeApexCallout {

   public static void invokeapexcallout(list<Net_Promoter__c> nps) {
public class Futureapexcallout{

  public static void apexcallout(string Id){
  List<String> EmailIds = '******'.split(',');

        pageReference pdfPage = Page.NPS_Survey;
        blob b = pdfpage.getContentaspdf(); 

        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();

        String addresses;
        email.setSubject( 'Check VF From PB' +String.valueOf(DateTime.now()));
        email.setToAddresses( EmailIds  );
        email.setPlainTextBody('Hi MD, Please see attached the current NPS for ***');
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});