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
SazEastSazEast 

standard controller and extension controller referencing issues

Hello,

I have a wrapper extension class that's intended to bring back grandchild records for a pageblock table within a Visualforce page. However, I keep getting errors when trying to save the Visualforce page referencing the extension controller. I'm not sure if there's a problem with the extension controller or the Visualforce page? Please see code below, any help is greatly appreciated!

VF Page:

<apex:page standardController="Consolidated_Invoicing__c" extensions="WrapperSarah"  renderas="pdf">

Extension Controller:

public class WrapperSarah{ 
private final Consolidated_Invoicing__c consinvs;
    public WrapperSarah(ApexPages.StandardController stdController) {
this.consinvs = (Consolidated_Invoicing__c)stdController.getRecord();
    }

Can provide the full code if needed but only getting errors after this has been added in following a salesforce guide.

Thanks!
Best Answer chosen by SazEast
Biswojeet Ray 11Biswojeet Ray 11

Hi Sarah

Please use this class.

public class WrapperSarah{ 

private final Consolidated_Invoicing__c consinvs;
    public WrapperSarah(ApexPages.StandardController stdController) {
       this.consinvs = (Consolidated_Invoicing__c)stdController.getRecord();
       WrapperSarah wrp = new WrapperSarah();
    }
    Id recordId;
    public List<Consolidated_Invoicing__c> consolidatedInvoiceList { get; set; }
    public List<Invoice__c> invoiceList { get; set; }
    public Map<Id, List<Invoice__c>> coninvIdinvListMap { get ; set; }
    Set<Id> invoiceIds = new Set<Id>();
    Id Consolidated_InvoiceId = ApexPages.currentPage().getParameters().get('consId');
    Map<Id, Consolidated_Invoicing__c> memberMap = new Map<Id, Consolidated_Invoicing__c>();
    public List<ConsolidatedInvoiceWrapperSarah> consolidatedInvoiceWrapperSarahList { get; set; }
    
    public WrapperSarah() {   
        consolidatedInvoiceList = [SELECT  Total__c, Name FROM Consolidated_Invoicing__c 
            Where Id =: ApexPages.currentPage().getParameters().get('id')];
        coninvIdinvListMap = new Map<Id, List<Invoice__c>>();
        consolidatedInvoiceWrapperSarahList = new List<ConsolidatedInvoiceWrapperSarah>();
        if(consolidatedInvoiceList.size() > 0) {
            for (Consolidated_Invoicing__c cons: consolidatedInvoiceList) {
                invoiceIds.add(cons.Id);
                memberMap.put(cons.Id, cons);
            }
            invoiceList = [SELECT Name, Consolidated_Invoice__c, Patient_Name__c, Hospital_Treated__c, Policy_Number__c, (SELECT Name, Charge_Description__c, Net_Price__c, Gross_Price__c, Line__c, Quantity__c, VAT__c, Date__c FROM Treatments__r) 
                FROM Invoice__c 
                WHERE Consolidated_Invoice__c IN : invoiceIds];
            system.debug('Invoice List is ' + invoiceList);
        }
        if(invoiceList.size() > 0) {
            for(Invoice__c intrst : invoiceList) {
                if(!coninvIdinvListMap.containsKey(intrst.Consolidated_Invoice__c)){
                    coninvIdinvListMap.put(intrst.Consolidated_Invoice__c, new List<Invoice__c>());
                }
                coninvIdinvListMap.get(intrst.Consolidated_Invoice__c).add(intrst);
            }
            for(Id invoiceId : coninvIdinvListMap.keySet()) {
                consolidatedInvoiceWrapperSarahList.add(new ConsolidatedInvoiceWrapperSarah(memberMap.get(invoiceId), coninvIdinvListMap.get(invoiceId)));
            }
        }        
    }     
    public class ConsolidatedInvoiceWrapperSarah{
        public Consolidated_Invoicing__c consinv { get; set; }
        public List<Invoice__c> invclist { get; set; }        
        public ConsolidatedInvoiceWrapperSarah(Consolidated_Invoicing__c consinv, List<Invoice__c> invclist) {
            this.consinv= consinv;
            this.invclist = invclist;
        }    
}
}

 

Kindly let me know if it helps you and please mark as Best Answer.

Thanks and Regards,
Biswojeet

All Answers

Biswojeet Ray 11Biswojeet Ray 11

Hi Sarah,

 

Please send full code and error message.

 

Thanks,

Raj VakatiRaj Vakati
what is the error message?

Change your code like below and try once

public class WrapperSarah{ 
public Consolidated_Invoicing__c consinvs;
    public WrapperSarah(ApexPages.StandardController stdController) {
this.consinvs = (Consolidated_Invoicing__c)stdController.getRecord();
    }
Ramesh DRamesh D
Hi Sarah,

Nothing wrong with your code and it worked perfectly fine for me, can you please let us know what's the error you are getting? so we can help you out if we can
<apex:page standardController="Property__c" extensions="WrapperSarah"  renderas="pdf">
   <apex:form >
    Hello <apex:inputField value="{!Property__c.Address__c}" />
    <br /><apex:commandButton value="Submit" action="{!save}" />
</apex:form>
</apex:page>
Controller:
public class WrapperSarah{ 
    private final Property__c consinvs;
    public WrapperSarah(ApexPages.StandardController stdController) {
        this.consinvs = (Property__c)stdController.getRecord();
    }
}
Output:
User-added image


Thanks
Ramesh
SazEastSazEast
Thanks - your help is much appreciated! Please see full code below:

Wrapper Class:

public class WrapperSarah{ 

private final Consolidated_Invoicing__c consinvs;
    public WrapperSarah(ApexPages.StandardController stdController) {
       this.consinvs = (Consolidated_Invoicing__c)stdController.getRecord();
    }
Id recordId;
    public List<Consolidated_Invoicing__c> consolidatedInvoiceList { get; set; }
    public List<Invoice__c> invoiceList { get; set; }
    public Map<Id, List<Invoice__c>> coninvIdinvListMap { get ; set; }
    Set<Id> invoiceIds = new Set<Id>();
    Id Consolidated_InvoiceId = ApexPages.currentPage().getParameters().get('consId');
    Map<Id, Consolidated_Invoicing__c> memberMap = new Map<Id, Consolidated_Invoicing__c>();
    public List<ConsolidatedInvoiceWrapperSarah> consolidatedInvoiceWrapperSarahList { get; set; }
    public WrapperSarah() {   
        consolidatedInvoiceList = [SELECT  Total__c, Name FROM Consolidated_Invoicing__c Where Id =: ApexPages.currentPage().getParameters().get('id')];
        coninvIdinvListMap = new Map<Id, List<Invoice__c>>();
        consolidatedInvoiceWrapperSarahList = new List<ConsolidatedInvoiceWrapperSarah>();
        if(consolidatedInvoiceList.size() > 0) {
            for
            (Consolidated_Invoicing__c cons: consolidatedInvoiceList) {
                invoiceIds.add(cons.Id);
                memberMap.put(cons.Id, cons);
            }
            invoiceList = [SELECT Name, Consolidated_Invoice__c, Patient_Name__c, Hospital_Treated__c, Policy_Number__c, (SELECT Name, Charge_Description__c, Net_Price__c, Gross_Price__c, Line__c, Quantity__c, VAT__c, Date__c FROM Treatments__r) FROM Invoice__c WHERE Consolidated_Invoice__c IN : invoiceIds];
            system.debug('Invoice List is ' + invoiceList);
        }
        if(invoiceList.size() > 0) {
            for(Invoice__c intrst : invoiceList) {
                if(!coninvIdinvListMap.containsKey(intrst.Consolidated_Invoice__c)){
                    coninvIdinvListMap.put(intrst.Consolidated_Invoice__c, new List<Invoice__c>());
                }
                coninvIdinvListMap.get(intrst.Consolidated_Invoice__c).add(intrst);
            }
            for(Id invoiceId : coninvIdinvListMap.keySet()) {
                consolidatedInvoiceWrapperSarahList.add(new ConsolidatedInvoiceWrapperSarah(memberMap.get(invoiceId), coninvIdinvListMap.get(invoiceId)));
            }
        }        
    }     
    public class ConsolidatedInvoiceWrapperSarah{
        public Consolidated_Invoicing__c consinv { get; set; }
        public List<Invoice__c> invclist { get; set; }        
        public ConsolidatedInvoiceWrapperSarah(Consolidated_Invoicing__c consinv, List<Invoice__c> invclist) {
            this.consinv= consinv;
            this.invclist = invclist;
        }    
}
}


VisualForce Page:

<apex:page standardController="Consolidated_Invoicing__c" extensions="WrapperSarah"  renderas="pdf">
<apex:form >
<apex:pageBlock >        
        <apex:pageBlockTable value="{!ConsolidatedInvoiceWrapperSarahList}" var="W">
        <apex:column headerValue="Consolidated Invoice Number" value="{!W.consinv.Name}"/>
                <apex:column >
            <apex:pageblockTable value="{!W.invclist }" var="I">               
                <apex:column value="{!I.Patient_Name__c}"/>
                <apex:column value="{!I.Policy_Number__c}"/>
                <apex:column value="{!I.Hospital_Treated__c}"/>           
                <apex:column >
                    <apex:pageBlockTable value="{!I.Treatments__r}" var="E">
                        <apex:column value="{!E.Name}"/>
                        <apex:column value="{!E.Charge_Description__c}"/>
                        <apex:column value="{!E.Quantity__c}"/>
                        <apex:column value="{!E.Gross_Price__c}"/>
                        <apex:column value="{!E.VAT__c}"/>
                        <apex:column value="{!E.Net_Price__c}"/>
                    </apex:pageBlockTable>
                </apex:column>                
            </apex:pageblockTable>
           </apex:column>
          </apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>



This should then produce a consolidated invoice pdf showing a table of related invoices (child) and treatments(grandchild) to the Consolidated Invoice (Parent) but this is all that i'm getting when previewing with a record id with no table data showing:

User-added image

Thank you
Biswojeet Ray 11Biswojeet Ray 11

Hi Sarah

Please use this class.

public class WrapperSarah{ 

private final Consolidated_Invoicing__c consinvs;
    public WrapperSarah(ApexPages.StandardController stdController) {
       this.consinvs = (Consolidated_Invoicing__c)stdController.getRecord();
       WrapperSarah wrp = new WrapperSarah();
    }
    Id recordId;
    public List<Consolidated_Invoicing__c> consolidatedInvoiceList { get; set; }
    public List<Invoice__c> invoiceList { get; set; }
    public Map<Id, List<Invoice__c>> coninvIdinvListMap { get ; set; }
    Set<Id> invoiceIds = new Set<Id>();
    Id Consolidated_InvoiceId = ApexPages.currentPage().getParameters().get('consId');
    Map<Id, Consolidated_Invoicing__c> memberMap = new Map<Id, Consolidated_Invoicing__c>();
    public List<ConsolidatedInvoiceWrapperSarah> consolidatedInvoiceWrapperSarahList { get; set; }
    
    public WrapperSarah() {   
        consolidatedInvoiceList = [SELECT  Total__c, Name FROM Consolidated_Invoicing__c 
            Where Id =: ApexPages.currentPage().getParameters().get('id')];
        coninvIdinvListMap = new Map<Id, List<Invoice__c>>();
        consolidatedInvoiceWrapperSarahList = new List<ConsolidatedInvoiceWrapperSarah>();
        if(consolidatedInvoiceList.size() > 0) {
            for (Consolidated_Invoicing__c cons: consolidatedInvoiceList) {
                invoiceIds.add(cons.Id);
                memberMap.put(cons.Id, cons);
            }
            invoiceList = [SELECT Name, Consolidated_Invoice__c, Patient_Name__c, Hospital_Treated__c, Policy_Number__c, (SELECT Name, Charge_Description__c, Net_Price__c, Gross_Price__c, Line__c, Quantity__c, VAT__c, Date__c FROM Treatments__r) 
                FROM Invoice__c 
                WHERE Consolidated_Invoice__c IN : invoiceIds];
            system.debug('Invoice List is ' + invoiceList);
        }
        if(invoiceList.size() > 0) {
            for(Invoice__c intrst : invoiceList) {
                if(!coninvIdinvListMap.containsKey(intrst.Consolidated_Invoice__c)){
                    coninvIdinvListMap.put(intrst.Consolidated_Invoice__c, new List<Invoice__c>());
                }
                coninvIdinvListMap.get(intrst.Consolidated_Invoice__c).add(intrst);
            }
            for(Id invoiceId : coninvIdinvListMap.keySet()) {
                consolidatedInvoiceWrapperSarahList.add(new ConsolidatedInvoiceWrapperSarah(memberMap.get(invoiceId), coninvIdinvListMap.get(invoiceId)));
            }
        }        
    }     
    public class ConsolidatedInvoiceWrapperSarah{
        public Consolidated_Invoicing__c consinv { get; set; }
        public List<Invoice__c> invclist { get; set; }        
        public ConsolidatedInvoiceWrapperSarah(Consolidated_Invoicing__c consinv, List<Invoice__c> invclist) {
            this.consinv= consinv;
            this.invclist = invclist;
        }    
}
}

 

Kindly let me know if it helps you and please mark as Best Answer.

Thanks and Regards,
Biswojeet

This was selected as the best answer
SazEastSazEast
Thanks for the class, this appears to be working fine but the visualforce page only seems to be working with "WrapperSarah" as the Controller rather than as an extension Controller. 

As a controller, the table is successfully displayed with the required data using a VF page starting with:

<apex:page Controller="WrapperSarah" renderas="pdf">

But I need to use the wrapper as an extension as per my original visualforce page code in order to reference standard controller functionality too.

<apex:page standardController="Consolidated_Invoicing__c" extensions="WrapperSarah"  renderas="pdf">

This doesn't seem to be instantiating the extension class as no table is diplayed on the pdf. Is there anything obvious that I'm missing with referencing the extension?

Thanks so much for your help!
Lucas Wright 12Lucas Wright 12
I'm not sure if it's possible to use a standard controller and an extention controller to reference fields on the grandparent object