You need to sign in to do that
Don't have an account?
Linda 98
Custom button to Generate PDF,Save it in attachments and email it.
Hi i am having a custom button,which when clicked generates the PDF and saves it in attachment.
Now i am trying to make it as email too.
so when the custom button is clicked,generate pdf ,save the pdf to attachment and email it to particular user email.
How can i do it?Can i do it on single button?Or do i need two buttons. 1 .generate and save
2.email pdf?
I am confused and struck here .I am able to generate it and save as attachment.
But i want all three steps(generate,save and email) in single button.Please help.
Thanks in advance.
Now i am trying to make it as email too.
so when the custom button is clicked,generate pdf ,save the pdf to attachment and email it to particular user email.
How can i do it?Can i do it on single button?Or do i need two buttons. 1 .generate and save
2.email pdf?
I am confused and struck here .I am able to generate it and save as attachment.
But i want all three steps(generate,save and email) in single button.Please help.
Thanks in advance.
First, if you are trying to generate a custom PDF on Salesforce from a Visualforce Page, then you will need to develop the needed Visualforce Page, and its related controller, if necessary.
Then you will need to create a class that exposes a webservice method and does a couple of things:
1. It will need to call the page - using the PageReference.getContentAsPDF() method. This will return a Blob
2. You can then create the Attachment Record (using the Blob returned from the previous step) and relate it to the Parent Record. Save this.
3. You can also then use the Blob record to create the EmailAttachment and then create the email and send it off.
Once this is complete, you will need to create your button, which is essentially a javascript button that will use the sforce javascript library to call the method that is exposed as a web service.
Below is an example of the class that will generate the PDF, Save the attachement, and email it:
Below is an example of what Javascript would go into the button:
There you have it.
Error: Compile Error: Duplicate variable: att (attempt to re-create the variable with type: EmailFileAttachment) at line 20 column 39
Can you share the code that you used for generating the PDF and saves it in attachment on within the record on Object please? I have a code on my custom object that creates the PDF file, however I would like when the button is selected that it also attaches the PDF to the record. Thanks.
Can you please help me with this? I am getting the error Variable doesnt exist quoteId.
in line 5, replace 'quoteId' with the name of the variable you are passing in as the Id. in my example, it would be 'recordId'. Hope that helps.
I am sorry to bother you again. What do you mean by variable you are passing in as the Id? I used recordId at the class and it did not give me an error but when i am creating a button the javascript gave me an error
Field record.Id does not exist. Check spelling.
If i post my VF page & class code will it help you?
I really appreciate your help.
I was able to fix the issue after playing around. One question about mess.setToAddresses(new String[]{'somebody@blah.com'});
what should be the value for 'somebody@blah.com'? Can user type in an email address they want to send the document?
If you are calling this webservice class from a Visualforce button, then if you know a decent amount of Javascript, then you may be able to pop an input box and send the value of the input to the method call. You will need to add an additional parameter to the webservice method representing the email address in order to utilize it within the code. Best of luck to you. It seems like my answer is helping you, so please feel free to mark as 'Best Answer'. Thanks!
How did you fix that issue? I am also getting the same error.
Thanks,
AK
The Page "PDFPage" is a different VF page right? Because in my code i have a requirement like ApexPages.currentPage().getContentAsPDF(); it is throwing
"common.apex.runtime.impl.ExecutionException: Exception common.page.PageInterruptException, Cyclical server-side forwards detected: /apex/UpgradeAdvisor?inline=1"|0x72885936
Can you please help
Thanks,
Sayandip
Hey Ash!
I am getting the same error message, could you please tell us how you solved it?
Is that an Id that I should pass from the Visualforce Page or from the Record page?
Thanks a lot!
Sebastian