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
JN22JN22 

Open Commandbutton in new Window

Hello,

 

I have the following line of code in my VF page:

 

            <apex:commandButton value="Generate PDF" action="{!URLFOR($Page.AcctPlanPDF,null,[Id=Account_Plan__c.id])}" style="background:#99CCFF; font-weight=bold"/>

I would like this to open a pop-up window to the AcctPlanPDF page when the button is clicked.  Does anyone know how to accomplish this while maintaining the commandButton?  Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
BharathimohanBharathimohan

Hi ,

 

I believe that you want to place the "Generate PDF" button either on the Account_Plan__c Object layout or in the VisualForce page with Controller as Account_Plan__c. To open it new window, we need to go for window.open() as below

 

Try this code,


<apex:form >
<apex:commandButton value="Generate PDF" onclick="window.open('/apex/AcctPlanPDF?id='+'{!Account_Plan__c.Id}','_blank','height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" style="background:#99CCFF; font-weight=bold" />
</apex:form>

 

This should work, let me know in case of any issues.

 

Please mark this post as solved, if it helps you.

 

Regards,

Bharathi
Salesforce For All

 

All Answers

BharathimohanBharathimohan

Hi ,

 

I believe that you want to place the "Generate PDF" button either on the Account_Plan__c Object layout or in the VisualForce page with Controller as Account_Plan__c. To open it new window, we need to go for window.open() as below

 

Try this code,


<apex:form >
<apex:commandButton value="Generate PDF" onclick="window.open('/apex/AcctPlanPDF?id='+'{!Account_Plan__c.Id}','_blank','height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" style="background:#99CCFF; font-weight=bold" />
</apex:form>

 

This should work, let me know in case of any issues.

 

Please mark this post as solved, if it helps you.

 

Regards,

Bharathi
Salesforce For All

 

This was selected as the best answer
JN22JN22

Thanks Bharathi, that worked like a charm!!

k sfdck sfdc
Hi Bharathi Mohan,

<apex:commandButton value="Generate PDF" onclick="window.open('/apex/AcctPlanPDF?id='+'{!Account_Plan__c.Id}','_blank','height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" style="background:#99CCFF; font-weight=bold" />


                              Please give 2 more variables Example in above Command button