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
SHAIK MOHAMMAD YASEENSHAIK MOHAMMAD YASEEN 

I have a custom button on my custom object. on click of the button it will redirected to a vfpage. now my requirement is on click of the button i have to download the VFpage as PDF

Hi All,

I have a requirement where i have created a custom button on the detail page of any record of a custom object. on click of the button a new window will be opeened with a VF page rendering as PDF. now my requirement is to download the page with out displaying the page. I mean on click of the button the VF page should be downloaded.

Please note the data is generated in the VF page based on the record id of the record which is being passed to page on click of the custom button.

BEst Regards,
Mohammad Yaseen
Lokesh KumarLokesh Kumar
Hi Shaik,

Use like below working code.
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

var session = "{!$Api.Session_ID}"; 
sforce.apex.execute("yourvfpage","generatePdf",  // change the page name
{idList:"{!yourCustomObj.Id}",  //change as per your object api name
sessionId:session}); 
location.reload();

-Lokesh
Lokesh KumarLokesh Kumar
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

var session = "{!$Api.Session_ID}"; 
sforce.apex.execute("yourControllerClass","yourControllermethod",  // change the controller name and method to generate pdf
{idList:"{!yourCustomObj.Id}",  //change as per your object api name
sessionId:session}); 
location.reload();
Apologies for wrong code kindly use above latest one.

-Lokesh
 
Arvind KumarArvind Kumar
Hi Yaseen,

It is very simple. Please follow the below blog. You will get solution of your requirement.

http://salesforcemaniacs.blogspot.in/2016/01/detail-page-button-to-show-pdf-file-in.html

If you have any query please let me know.

Thanks,
Arvind Kumar