+ Start a Discussion
salesforcerrrsalesforcerrr 

Visualforce Page Attachment via Invokable Method

Hi, 

the below class is invoked via Process builder and meant to email a dynamic visualforce attachment. 
 
public class EmailInvoked {

    @InvocableMethod
    public static void sendEmail(List<Id> lstId){
        List<String> EmailIds = 'personal@example.com'.split(',');
        PageReference ref = Page.WorkDocket;
        Blob b ;
        b = ref.getContent();

        

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

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

        String addresses;
        email.setSubject( 'Check VF From PB' +String.valueOf(DateTime.now()));
        email.setToAddresses( EmailIds  );
        email.setPlainTextBody('Hey there, I am an email Body');
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }
}

However, I would need to 
1. Not only have this email send to a static address but based on a field in the Case - Site_Email__c 
2. The Visualforce page is currently attached but only the static contect. For example apex:output fields are not rendered. How do i get the ID in the visualforce page to render correctly? 

Thank you. All help much appreciated. 
 
sukanya banekarsukanya banekar
Hi,

To set email id dynamically from case record you need to query on case record with lstId (I hope they are id's of case). You can get email field and add the same in list of email id.

I am not getting your 2nd question can you elaborate?

Thanks,
Sukanya Banekar