0

I am not sure what I am doing wrong here.

Here is my controller class which acts as a controller class for the visual force page and also has an invocable method -

public without sharing class PDFGeneratorInvocableController {

    static List<String> workOrderIds = new List<String>();
    public List<PDFVendorQuoteDataFields> pdfVendorQuoteDataFieldsList { get; set; }
    // static List<Vendor_Quote_Line_Item__c> vendorQuoteLineItems = new List<Vendor_Quote_Line_Item__c>();
    static List<ContentVersion> pdfFiles = new List<ContentVersion>(); 
    static List<ContentDocumentLink> contentDocumentLinks = new List<ContentDocumentLink>();

    @InvocableMethod(label='PDF Generator' description='PDF Generator')
    public static void pdfGenerator(List<Requests> inputRequests) {
        PDFGeneratorInvocableController controller = new PDFGeneratorInvocableController();
        
        for (PDFGeneratorInvocableController.Requests request : inputRequests) {
            if (request.workOrderId != null) {
                workOrderIds.add(request.workOrderId);
            }
        }

        List<Vendor_Quote_Line_Item__c> vendorQuoteLineItems = [SELECT Id, 
            Vendor_Quote__r.Vendor_Name__r.Name,
            Vendor_Quote__r.Work_Order_ID__c,
            Vendor_Quote__r.Work_Order_ID__r.WorkOrderNumber,
            //Vendor Quote Line Items
            Product_Name__r.ProductCode, 
            Product_Name__r.Name, 
            Product_Family__c, 
            Quantity__c,       
            Unit_Price__c 
            FROM Vendor_Quote_Line_Item__c WHERE Vendor_Quote__r.Work_Order_ID__c IN :workOrderIds AND Vendor_Quote__r.Status__c = 'Approved'];

        controller.generatePDFHeaderValues(vendorQuoteLineItems);   
    }

    private void generatePDFHeaderValues(List<Vendor_Quote_Line_Item__c> vendorQuoteLineItems) {
        Map<String, PDFVendorQuoteDataFields> workOrderIdToDataFields = new Map<String, PDFVendorQuoteDataFields>();
        for (Vendor_Quote_Line_Item__c vql : vendorQuoteLineItems) {
            String workOrderId = vql.Vendor_Quote__r.Work_Order_ID__c;
            PDFVendorQuoteDataFields pdfVendorQuoteDataFields;
            if (!workOrderIdToDataFields.containsKey(workOrderId)) {
                pdfVendorQuoteDataFields = new PDFVendorQuoteDataFields();
                pdfVendorQuoteDataFields.vendorQuoteLineItems = new List<PDFVendorQuoteLineItemDataFields>();
                pdfVendorQuoteDataFields.workOrderId = workOrderId;
                pdfVendorQuoteDataFields.workOrderNumber = vql.Vendor_Quote__r.Work_Order_ID__r.WorkOrderNumber;
                pdfVendorQuoteDataFields.vendorName = vql.Vendor_Quote__r.Vendor_Name__r.Name;
            
                workOrderIdToDataFields.put(workOrderId, pdfVendorQuoteDataFields);
            } else {
                pdfVendorQuoteDataFields = workOrderIdToDataFields.get(workOrderId);
            }
            PDFVendorQuoteLineItemDataFields lineItem = new PDFVendorQuoteLineItemDataFields();
            lineItem.productCode = vql.Product_Name__r.ProductCode;
            lineItem.productName = vql.Product_Name__r.Name;
            pdfVendorQuoteDataFields.vendorQuoteLineItems.add(lineItem);
        }
        pdfVendorQuoteDataFieldsList.clear();
        pdfVendorQuoteDataFieldsList.addAll(workOrderIdToDataFields.values());
    }


    public class Requests {
        @InvocableVariable(label='Work Order Id' required=true)
        public String workOrderId;
    }

    public class PDFVendorQuoteDataFields {
        public String workOrderId { get; set; }
        public String workOrderNumber { get; set; }
        public String vendorName { get; set; }
        public List<PDFVendorQuoteLineItemDataFields> vendorQuoteLineItems { get; set; }
    }

    public class PDFVendorQuoteLineItemDataFields {
        public String productCode { get; set; }
        public String productName { get; set; }
        public String productFamily { get; set; }
        public Decimal quantity { get; set; }
        public Decimal unitPrice { get; set; }
    }
}

Visual force page - The issue I am not able to access the pdfVendorQuoteDataFieldsList class variable which has a line items list.

<apex:page controller="PDFGeneratorInvocableController" renderAs="pdf">
    <table style="font-family:sans-serif; font-size: 14px; padding-left:10px; padding-right:10px; width: 100%;">
        <tbody>
            <apex:repeat value="{!pdfVendorQuoteDataFieldsList}" var="vendorQuote" id="lineItems">
                <apex:repeat value="{!vendorQuote.vendorQuoteLineItems}" var="item" id="lineItems">
                    <tr style="font-size: 14px; page-break-inside: avoid;">
                        <td style="border: 1px solid rgb(236, 236, 236); padding: 5px;">
                            <div style="background-color: #f7f7f7 ; padding: 3px;">
                                <b>Code:</b> {!item.Product_Name__r.ProductCode}&nbsp;&nbsp;&nbsp;
                            </div>
                            <div style="margin-top: 5px;padding: 2px;">
                                <b>Description:</b>
                                <span style="flex-grow: 1; line-break: anywhere;  font-size: 11px;">{!item.Product_Name__r.Name}</span>
                            </div>
                        </td>           
                    </tr>
                </apex:repeat>
            </apex:repeat>       
        </tbody>
    </table>
</apex:page>

This is the error I get when I save the visual force page on vs code. [{

"message": "Unknown property 'PDFGeneratorInvocableController.PDFVendorQuoteLineItemDataFields'",

}]

EDITs made after cropedys answer Here I am able to retrieve every other data value. It is just the inner class values I am not able to access. But they print fine when I system.debug on those values.

Apex controller -

public without sharing class PDFGeneratorInvocableController {

    static List<String> workOrderIds = new List<String>();
    public List<PDFVendorQuote> pdfVendorQuotesList = new List<PDFVendorQuote>();

    static List<ContentVersion> pdfFiles = new List<ContentVersion>(); 
    static List<ContentDocumentLink> contentDocumentLinks = new List<ContentDocumentLink>();

    @InvocableMethod(label='PDF Generator' description='PDF Generator')
    public static void pdfGenerator(List<Requests> inputRequests) {
        PDFGeneratorInvocableController controller = new PDFGeneratorInvocableController();
        
        for (PDFGeneratorInvocableController.Requests request : inputRequests) {
            if (request.workOrderId != null) {
                workOrderIds.add(request.workOrderId);
            }
        }

        List<Vendor_Quote_Line_Item__c> vendorQuoteLineItems = [SELECT Id, 
            Vendor_Quote__r.Vendor_Name__r.Name,
            Vendor_Quote__r.Work_Order_ID__c,
            Vendor_Quote__r.Work_Order_ID__r.WorkOrderNumber,
            //Vendor Quote Line Items
            Product_Name__r.ProductCode, 
            Product_Name__r.Name, 
            Product_Family__c, 
            Quantity__c,       
            Unit_Price__c 
            FROM Vendor_Quote_Line_Item__c WHERE Vendor_Quote__r.Work_Order_ID__c IN :workOrderIds AND Vendor_Quote__r.Status__c = 'Approved'];

        controller.generatePDFHeaderValues(vendorQuoteLineItems);   
    }

    private void generatePDFHeaderValues(List<Vendor_Quote_Line_Item__c> vendorQuoteLineItems) {
        Map<String, PDFVendorQuote> workOrderIdToDataFields = new Map<String, PDFVendorQuote>();
        for (Vendor_Quote_Line_Item__c vql : vendorQuoteLineItems) {
            String workOrderId = vql.Vendor_Quote__r.Work_Order_ID__c;
            PDFVendorQuote pdfVendorQuoteRecord;
            if (!workOrderIdToDataFields.containsKey(workOrderId)) {
                pdfVendorQuoteRecord = new PDFVendorQuote();
                pdfVendorQuoteRecord.vendorQuoteLineItems = new List<PDFVendorQuoteLineItem>();
                pdfVendorQuoteRecord.workOrderId = workOrderId;
                pdfVendorQuoteRecord.workOrderNumber = vql.Vendor_Quote__r.Work_Order_ID__r.WorkOrderNumber;
                pdfVendorQuoteRecord.vendorName = vql.Vendor_Quote__r.Vendor_Name__r.Name;
            
                workOrderIdToDataFields.put(workOrderId, pdfVendorQuoteRecord);
            } else {
                pdfVendorQuoteRecord = workOrderIdToDataFields.get(workOrderId);
            }
            PDFVendorQuoteLineItem lineItem = new PDFVendorQuoteLineItem();
            lineItem.productCode = vql.Product_Name__r.ProductCode;
            lineItem.productName = vql.Product_Name__r.Name;
            pdfVendorQuoteRecord.vendorQuoteLineItems.add(lineItem);
        }
        pdfVendorQuotesList.clear();
        pdfVendorQuotesList.addAll(workOrderIdToDataFields.values());
    }


    public class Requests {
        @InvocableVariable(label='Work Order Id' required=true)
        public String workOrderId;
    }

    public class PDFVendorQuote {
        public String workOrderId { get; set; }
        public String workOrderNumber { get; set; }
        public String vendorName { get; set; }
        public List<PDFVendorQuoteLineItem> vendorQuoteLineItems { get; set; }
    }

    public class PDFVendorQuoteLineItem {
        public String productCode { get; set; }
        public String productName { get; set; }
    }
}

Visual force Page - Here I am able to retrieve every other data value. It is just the inner class values I am not able to access.

<apex:page controller="PDFGeneratorInvocableController" renderAs="pdf">
    <table style="font-family:sans-serif; font-size: 14px; padding-left:10px; padding-right:10px; width: 100%;">
        <tbody>
            <apex:repeat value="{!pdfVendorQuotesList}" var="vendorQuote" id="lineItems">
                <apex:repeat value="{!vendorQuote.vendorQuoteLineItems}" var="item" id="lineItems">
                    <tr style="font-size: 14px; page-break-inside: avoid;">
                        <td style="border: 1px solid rgb(236, 236, 236); padding: 5px;">
                            <div style="background-color: #f7f7f7 ; padding: 3px;">
                                <b>Code:</b> {!item.productCode}&nbsp;&nbsp;&nbsp;
                            </div>
                            <div style="margin-top: 5px;padding: 2px;">
                                <b>Description:</b>
                                <span style="flex-grow: 1; line-break: anywhere;  font-size: 11px;">{!item.productName}</span>
                            </div>
                        </td>           
                    </tr>
                </apex:repeat>
            </apex:repeat>       
        </tbody>
    </table>
</apex:page>

Here is the new error - [{ "message": "Unknown property 'PDFGeneratorInvocableController.pdfVendorQuotesList'", }]

0

1 Answer 1

3
  • {!pdfVendorQuoteDataFieldsList} refers to controller property public List<PDFVendorQuoteDataFields> pdfVendorQuoteDataFieldsList { get; set; }

  • PDFVendorQuoteDataFields refers to inner class public class PDFVendorQuoteDataFields that in turn has

    • public List<PDFVendorQuoteLineItemDataFields> vendorQuoteLineItems { get; set; } property that you are iterating over.
  • That inner class is defined as:

        public String productCode { get; set; }
        public String productName { get; set; }
        public String productFamily { get; set; }
        public Decimal quantity { get; set; }
        public Decimal unitPrice { get; set; }
    }

Yet you are attempting to display (by iterating over item)

{!item.Product_Name__r.ProductCode}

but there is no Product_Name__r relationship in PDFVendorQuoteLineItemDataFields

So, several possibilities

  1. The VF controller you posted hasn't been saved to the server
  2. The VF controller is out-of-date as you are referencing fields that don't exist

In addition, as best practice, class names should not be plural

  • Use PDFVendorQuote instead of PDFVendorQuoteDataFields
  • Use PDFVendorQuoteLineItem instead of PDFVendorQuoteLineItemDataFields
  • Use Request instead of Requests

plurals should be used for variables that are collections (lists, maps, sets)

7
  • I get it. The problem that I am having is that because of this error it wouldn't deploy. [{ "message": "Unknown property 'PDFGeneratorInvocableController.PDFVendorQuoteLineItemDataFields.Quantity__c'", }] Commented May 22 at 13:41
  • 1
    <b>Code:</b> {!item.Product_Name__r.ProductCode}&nbsp;&nbsp;&nbsp; references an instance of class PDFVendorQuoteLineItemDataFields. That class has no field Product_Name__r as you've already moved the sobject fields into inner class properties Commented May 22 at 15:38
  • cropredy - that was just a careless mistake. I even thought that would solve the issue I am having. I am still having issues accessing the inner class values which means the values of the PDFVendorQuoteLineItem class, I am able to access all the other values of the main class. I have added the new code to the original post. Please advise. Thanks Commented May 22 at 16:39
  • the new error is because this line public List<PDFVendorQuote> pdfVendorQuotesList = new List<PDFVendorQuote>(); is missing a {get; private set;}. Just because it is public doesn't make it visible to the VF page Commented May 22 at 17:03
  • Sorry cropredy I am just not able to make it work. Commented May 22 at 19:20

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.