0

Here is the SOQL to get the records -

Apex Class -

List<Vendor_Quote_Line_Item__c> vendorQuoteLineItems = [SELECT Id, 
            Product_Name__r.ProductCode, 
            Product_Name__r.Name, 
            FROM Vendor_Quote_Line_Item__c WHERE Vendor_Quote__r.Work_Order_ID__c = 'ID'];

Then I put the above vendorQuoteLineItems list as a page ref parameter like this -

PageReference pageRef = new PageReference('/apex/GeneratePDF');
pageRef.getParameters().put('vendorQuoteLineItems', JSON.serialize(vendorQuoteLineItems[0]));

Visual force -

On the visual force page I am trying to loop through the sobject records and list each item as a row in a table.

<apex:page>
    <table style="border: 1px solid black; border-collapse: collapse; width: 100%; font-family: sans-serif;">
        <thead>
            <tr style="background-color: #f2f2f2;">
                <th style="border: 1px solid black; padding: 5px;">Product Code</th>
                <th style="border: 1px solid black; padding: 5px;">Product Name</th>
            </tr>
        </thead>
        <tbody>
            <apex:repeat value="{!$CurrentPage.parameters.vendorQuoteLineItems}" var="item">
                <tr>
                    <td style="border: 1px solid black; padding: 5px;">{!item.Product_Name__r.Product_Code__c}</td>
                    <td style="border: 1px solid black; padding: 5px;">{!item.Product_Name__r.Name}</td>
                </tr>
            </apex:repeat>
        </tbody>
    </table>
</apex:page>

On the visual force page I am not setting any controller, everything on the page is displayed with the values from pageRef.

Except for the above I am displaying other values which are just single values not records and they work perfectly fine.

2
  • 2
    vendorQuoteLineItems as a page parameter is just a string, the apex:repeat value="xx" expects an Object that is a list. You'll need a controller that does the soql; the pageParameter should be the work_order_id__c's value Commented May 14 at 15:35
  • Thanks @cropredy Commented May 14 at 16:35

1 Answer 1

1

The page parameter that you establish via

pageRef.getParameters().put('vendorQuoteLineItems', JSON.serialize(vendorQuoteLineItems[0]));

is just a string.

The VF apex:repeat value="xx" attribute expects xx to be an Object of type List. apex:repeat doc

So, you're going to need the following:

  1. Pass the recordId as a parameter
PageReference pageRef = new PageReference('/apex/GeneratePDF');
pageRef.getParameters().put('workOrderId', theRecordIdOfWorkOrder);
  1. Change the apex:page for GeneratePDF to reference a controller (e.g. controller="GeneratePDFController"

  2. In that controller, create an Apex property

public Vendor_Quote_Line_Item__c[] vendorQuoteLineItems {
  get {
    return [SELECT Id, 
            Product_Name__r.ProductCode, 
            Product_Name__r.Name, 
            FROM Vendor_Quote_Line_Item__c WHERE Vendor_Quote__r.Work_Order_ID__c = 
    :ApexPages.currentPage().getParameters('workOrderId')];
  }
  private set;
}
  1. Change your VF page to reference this public property
<apex:repeat value="{!vendorQuoteLineItems}" var="item">

Now, it wasn't clear to me why you were serializing only a single Vendor_Quote_Line_Item__c so I omitted that in the above.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.