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
BellaBella 

Page & Controller for multiple PDF pages

Hi, I'm wondering if someone can help me out with an interesting issue. I have a custom button on a custom object that, when pressed, generates a single page pdf with inform from both that object and its child objects. Let's say sales orders and sales order line items. The controller is very simple: select sales order with sf id from the current page, then select all sales order line items which reference this sales order. Whole thing works great.

 

Now I would like to have a button on the sales order front view. I'd like to select sales orders from the view, press the button, and generate pdfs for all the sales orders and sales order line items in the same way. A sequence of connected pages (one per group of sales order + its line items)  would be great or multiple single page popup would also work. Basically I'm trying to get many pages without going to each individual sales order and clicking on the button.

 

Here's what I have so far:

 

1)      I know I need to use the ApexPages.StandardSetController to get the button on the view. That’s done and the button does appear there.

2)      I can select all the sales orders and make a map of sales orders to a list of its corresponding line items.

 

What I’m having trouble with:

 

1)      Picking only the selected sales orders. I keep trying to use the getSelected(); function on the ApexPages.StandardSetController, but it’s not working. Again, in my controller I want to get a list of only the items I picked in the view.

2)      Once I have that, I have trouble understanding how to pass everything to the visual force page, how to modify it so that it goes through the list of sales orders per page, then picks up the list of corresponding line items using the maps.

 

Can anyone help with this? Give me some guidance? Thank you!

dnakonidnakoni

I assume you have a special Visualforce page that does the PDF processing (renderas=pdf)?

 

If you, here is one way to do it. Basically instantiate the PDF page in code and pass to it the ID of the sales order. Here again I assume that once the PDF page has the ID of a sales order, it gets the line items by itself.

 

 

         PageReference pdf =  Page.PDF_PAGE;
         pdf.getParameters().put('id',SALESINVOICEID); 
         pdf.setRedirect(true);
         
         Blob b = pdf.getContent();
         
         
        Attachment a = new Attachment();
        a.Body = b;
        a.Name = 'PDF';
        a.ParentId = SALESINVOICEID;
        
        insert a;

 Here I create a new Attachment to attach it to the sales invoice, but you should get the idea of what to do.

 

 

 

BellaBella

Thanks, but that's not quite what I need. I need to pop up (not attach) a pdf with multiple pages, one for each sales order and its corresponding line items. It should look as if you went to each individual sales order, clicked the generate pdf button, and strung them all together.

 

Also, I need to make sure it’s done only for the sales orders selected in the view, not all of them.

 

Ok the selection issue is solved with {!GETRECORDIDS( $ObjectType.[object in question])}; function.