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
miteshsuramiteshsura 

Auto select pdf template for Quote

Hi,

 

Based on certain fields, I want to auto select the template, can that be done. 

Lets say, if value in field-A is NA, when user hits generate pdf, it should auto select NA Quote template. 

And if value in the field is EMEA, EMEA quote template shuld be auto selected. 

 

thanks for the help.

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Ah I got it! I think you can do this.

 

Create an IFrame which will be having a frame with the desired URL and on IFrame there will be a button "Save to Quote". As soon as you click on "Save to Quote" it will get the content from that URL and save it as PDF.

 

Basically PDF in IFram is just for the display, and more work if for the controller of the IFrame.

 

I hope you got my point.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Ankit AroraAnkit Arora

No, this feature is not available.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

miteshsuramiteshsura
Yes, not out of box. But I was thinking to have a custom button and popup the PDF when a user hits it.
I do a custom button but it just opens the PDF in the window with no option to save.
Thais for the tIme
Ankit AroraAnkit Arora

Are you opening a new visualforce page which have renderAs='PDF' or some change with the url?

 

I think in both cases when the pdf is generated you can save it with two option :

 

1) Check at bottom right side when you mouseover that section some option to save will appear.

2) If above one didn't work for you then you can right click on the PDF and saveAs.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

miteshsuramiteshsura

Probably I did not explain it properly. 

 

What I want is it to save the pdf under the quotes like SF has it now, but just bypass the selcting the template.

I can dynamically generate the URL (with passing right tempalte SF id) for the pdf when I hit the button, but it opens a pdf in a browser just like any another pdf. Yes, I see the oprtions in lower right hand side, but that would save the pdfs on a pc not under Quotes.

 

Makes sense? 

Ankit AroraAnkit Arora

Ah I got it! I think you can do this.

 

Create an IFrame which will be having a frame with the desired URL and on IFrame there will be a button "Save to Quote". As soon as you click on "Save to Quote" it will get the content from that URL and save it as PDF.

 

Basically PDF in IFram is just for the display, and more work if for the controller of the IFrame.

 

I hope you got my point.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
miteshsuramiteshsura

I am new to iFrame. Any pointers? From what you meantioned looks like a possible solution.

 

Many thanks. 

Ankit AroraAnkit Arora

It is very simple in salesforce. Just create a visualforce page which will act as outer frame including the button. And embed 

 

<apex:iframe src="http://www.salesforce.com" scrolling="true" id="theIframe"/>

 in your visualforce page, change SRC to your desired URL. The IFrame will display the PDF and on click on button on outer frame you can get the content from the URL.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

miteshsuramiteshsura
I will try that and see how it goes. I would also need a controller
For that vf page right? That will do the logic to actually save the PDF to
the quotes section
Ankit AroraAnkit Arora

Indeed!! And to get content you can use getContentAsPDF(), hope this will help you :

 

A good link where you can find definitions : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

miteshsuramiteshsura

So I was able to popup a window and show the pdf document. But for some reason the Pdf contents are not properly stored when I try to save it. Here is my

 

VF Page:

<apex:page standardController="Quote" showHeader="false" extensions="quotePDFExtension" action="{!pupulateURL}" title="PDF Preview">

				
	<script type='text/javascript'>
	</script>
	
	<apex:form >	
		<apex:pageBlock >
            <apex:pageBlockButtons >
				<apex:commandButton action="{!savePDF}" onkeyup="window.opener.location.reload();" value="Save to Request" id="btnSave" />
				<apex:commandButton onclick="window.close()" value="Cancel" id="btnCancel" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="PDF Preview" columns="1" collapsible="false">                
				<apex:iframe src="{!pdfURL}" scrolling="true" id="theIframe"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
		
	</apex:form>
	
</apex:page>

 Controller:

 

    //Saves the PDF to the quote
    public void savePDF(){
    	
    	Blob pdf = ApexPages.currentPage().getContentAsPDF();
    	System.debug('content:' + pdf);
    	
    	QuoteDocument doc = new QuoteDocument(Document=pdf, QuoteId=q.id); 
        insert doc;
    	
    }

 

Any thoughts? I have opened a ticket with SF too.

 

Thanks for the time, really appreciate it.

Ankit AroraAnkit Arora

Can you please elaborate more which data is expected to get stored and is not getting stored?

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

miteshsuramiteshsura

So using a custom button, it popup the VF page that has the quote in PDF format. When I hit "Save to Request" button on that VF page, it does save a pdf file, under Request (Quote object), but the content is something else, not the PDF. The code for saving the PDF is in previous post.

miteshsuramiteshsura

I got the solution, I was passing the entire VF page for the content, I just needed to pass the iFrame which has the PDF file.

With that change I am able to safe it as PDF as I like to.

 

Any idea on how can close the VF popup and auto refresh the Quote page, so it shows the PDF file that was just saved. As of now I have to manualy close the popup and refresh the parent / quote window. Thanks.

Ankit AroraAnkit Arora

One solution is to use the javascript. From where you are opening this main window (which also contains IFrame) use model dialog which will not allow user to click on the parent window till the quote screen is not closed.

 

When user save the quote or close the window you can apply javascript (window.location.href = window.location.href) to refresh the parent window.

 

So there are many option to go with. So if my approach helps you in any way then can you please mark it as solution, so others may get benefit :)

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

miteshsuramiteshsura

I was showing a vf page from that button. I created new button that executes
JavaScript and I have this code to popup a modal win but it stills shows normal
Window

OnClick JavaScript {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

window.showModalDialog('https://c.cs1.visual.force.com/apex/quotePDF?scontrolCaching=1&id={!Quote.Id}')

 

Is there something else to it?