function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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 {

  @InvocableMethod
   public static void invokeapexcallout(list<Net_Promoter__c> nps) {
     Futureapexcallout.apexcallout(nps[0].id);
   }
}
 
public class Futureapexcallout{

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

        pageReference pdfPage = Page.NPS_Survey;
        pdfPage.getParameters().put('id',Id);
        blob b = pdfpage.getContentaspdf(); 

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

        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
        efa1.setFileName('NPS.pdf');
        efa1.setBody(b);

        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});
    }
}