[SalesForce] customize create pdf on quote based on a field on Quote

I have a custom field on quote which is a checkbox. I need a way to allow or disallow the pdf creation based on this field

If the checkbox is true then only allow the create pdf to fire otherwise give a alert to say need to set the checkbox to true.

Is there a way to call the standard functionality of create Pdf button? I can check the custom field value on Quote in javascript and based on it call the create pdf button functionality.

Any ideas how we can achieve this?

Best Answer

Do you have a custom controller for your Quote PDF generator? If not, you can easily create one by creating an extension of the existing one that has a boolean object linked to a checkbox. If the checkbox is true, then the PDF is created, if it's false, then the PDF is aborted. Before any work is done, the controller checks the status of the custom boolean object.

I'm sure you could similarly add that kind of logic into the VF page by adding a validation rule to the checkbox, but I've never done it that way myself. Or, as you've suggested, this could also be done via JavaScript by checking the state of the checkbox.