• Mat Tzetzos
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
We have a flow which creates Quote templates when we click a custom button called "Generate PDF". I am able to create a template when I try to debug the flow. But when I hit the GeneratePDF button it creates a blank PDF instead of PDF based on templates.

The below is my apex class which accepts two input parameters from the flow:
1. Quote ID
2. Template ID


public class generateQuotePdfDocument_2{

@InvocableMethod(label='Invoke Apex')
    public static void invokeThisMethod(List<FlowInputs> request) {
    
    createQuoteFutureMethod(request);
        
    }
    
    //input details that comes to apex from flow
    public class FlowInputs{
    
        @InvocableVariable
        public String qID;
        
        @InvocableVariable
        public String QuoteTemplateID;
        
    }
    

public static void createQuoteFutureMethod (List<FlowInputs> request) {
//Id of Quote record.
String QuoteID = request[0].qID;
//String QuoteID = '0Q0020000008VfGCAU';
 
//Id of quote Template
String templateID = request[0].QuoteTemplateID;
//String templateID = '0EH0M000000sssO';

system.debug('This is request object: '+request);
system.debug('This is request[0] object: '+request[0]);
 
//This Url create the pdf for quote
String quoteUrl = '/quote/quoteTemplateDataViewer.apexp?id=';
 
quoteUrl +=QuoteID;
 
quoteUrl +='&headerHeight=190&footerHeight=188&summlid=';
 
quoteUrl +=templateID ;
 
quoteUrl +='#toolbar=1&navpanes=0&zoom=90';
system.debug('This is quoteURL object: '+quoteUrl);
 
//Create pdf content
PageReference pg = new PageReference(quoteUrl) ;
 
//Document object of quote which hold the quote pdf
QuoteDocument quotedoc = new QuoteDocument(); 
 
//Get the content of Pdf.
Blob b = pg.getContentAsPDF() ;
 
//content assign to document
quotedoc.Document = b;
 
//assign quote id where pdf should attach
quotedoc.QuoteId = QuoteID ;
 
//insert the quotdoc
 insert quotedoc; 
 
 }}