You need to sign in to do that
Don't have an account?
Page.getContent() returning wrong page content - sending email from a VF page with attachment
Having some problems with sending an attachment via email from a VF page- I'm instantiating a second page (Page B) from within a first (Page A), and setting the email body to PageB.getContent(). However, it seems the getContent() function is returning the Page A, and not Page B.
I also have a link to Page B from Page A, and this renders/outputs properly.
Anyone have any ideas?
... PageReference excelPage = Page.PAGE B; excelPage.getParameters().put('year', selectedYear); excelPage.setRedirect(true); String fileName = 'foo.xls'; //Prepare attachment to quote Messaging.EmailFileAttachment emailAttachment = new Messaging.EmailFileAttachment(); emailAttachment.setFileName(fileName); emailAttachment.setBody(excelPage.getContent()); emailMsg.setFileAttachments(new List<Messaging.EmailFileAttachment>{emailAttachment}); Messaging.SendEmailResult[] sers = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {emailMsg}); ...