You need to sign in to do that
Don't have an account?
Laura Boyd 18
Add today's date to Visualforce page
Hi
I have a controller (shown below) which generates a PDF and sends it by email.
I am setting the file name in the line of:
All I want to do is add todays date to the the filename which I have tried as:
All is does is bolt the text of "{!Today()} to end of the filename rather than inserting the date.
Any ideas where I am going wrong?
I have a controller (shown below) which generates a PDF and sends it by email.
I am setting the file name in the line of:
attach.setFileName('POFile.pdf');
All I want to do is add todays date to the the filename which I have tried as:
attach.setFileName('POFile{!Today()}.pdf');
All is does is bolt the text of "{!Today()} to end of the filename rather than inserting the date.
Any ideas where I am going wrong?
public with sharing class SendPDFbyEmail { public SendPDFbyEmail (ApexPages.StandardController controller) { } //Set variable values public String EmailAddress {get;set;} public String eSubject{get;set;} public String eBody{get;set;} //Start mail process and set criteria for PDF public PageReference SendEmail() { Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage(); PageReference pdfGeneration=Page.Purchase_Order_PDF; pdfGeneration.SetRedirect(true); Blob b=pdfGeneration.getContent(); //Create attachment and set criteria Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment(); attach.setFileName('PoFile"{!Today()}".pdf'); attach.setBody(b); email.SetSubject(eSubject); email.SetPlainTextBody(eBody); email.setToAddresses(new String[] { EmailAddress }); email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach}); //Now Sending the Email Messaging.SendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); return null; } }
Try like below
attach.setFileName('PoFile'+System.today()+'.pdf');
Please try to update your code like below
Let us know if this will help you
All Answers
Try like below
attach.setFileName('PoFile'+System.today()+'.pdf');
Please try to update your code like below
Let us know if this will help you