Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
How do I display only the current record rather than all records of an object (consolidated invoicing in this instance) using a custom wrapper class and visualforce page with an apex pageblocktable that shows the related records to the current object record (ie, all invoices and then treatments related to Consolidated invoices)?

Parent: Consolidated Invoicing

Child: Invoice

GrandChild: Treatments

I've created a wrapper class:

public class Wrapper{ 

    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>();

    Map<Id, Consolidated_Invoicing__c> memberMap = new Map<Id, Consolidated_Invoicing__c>();

    

    public List<ConsolidatedInvoiceWrapper> consolidatedInvoiceWrapperList { get; set; }

    public Wrapper() {   

        consolidatedInvoiceList = [SELECT  Total__c, Name FROM Consolidated_Invoicing__c];

        coninvIdinvListMap = new Map<Id, List<Invoice__c>>();

        consolidatedInvoiceWrapperList = new List<ConsolidatedInvoiceWrapper>();

        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, (SELECT Name, Charge_Description__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()) {

                consolidatedInvoiceWrapperList.add(new ConsolidatedInvoiceWrapper(memberMap.get(invoiceId), coninvIdinvListMap.get(invoiceId)));

            }

        }

    } 

    

    public class ConsolidatedInvoiceWrapper{

        public Consolidated_Invoicing__c consinv { get; set; }

        public List<Invoice__c> invclist { get; set; }

        

        public ConsolidatedInvoiceWrapper(Consolidated_Invoicing__c consinv, List<Invoice__c> invclist) {

            this.consinv= consinv;

            this.invclist = invclist;

        }

    }

}

And the the Visualforce page:

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

<apex:form >

<apex:pageBlock >

    <apex:pageBlockTable value="{!consolidatedInvoiceWrapperList}" var="W">

        <apex:column headerValue="Consolidated Invoice Number" value="{!W.consinv.Name}"/>

        <apex:column headerValue="Total Amount Due" value="{!W.consinv.Total__c}"/>

        <apex:column >

            <apex:pageblockTable value="{!W.invclist }" var="I">

                <apex:column headerValue= "Invoice Number" value="{!I.Name}"/>

                <apex:column >

                    <apex:pageBlockTable value="{!I.Treatments__r}" var="E">

                        <apex:column headerValue="Charge Code" value="{!E.Name}"/>

                        <apex:column headerValue= "Description" value="{!E.Charge_Description__c}"/>

                    </apex:pageBlockTable>

                </apex:column>

            </apex:pageblockTable>

        </apex:column>

    </apex:pageBlockTable>

</apex:pageBlock>

</apex:form>

</apex:page>

Is there something obvious i'm missing?

Thanks

 
2 answers
  1. Apr 11, 2019, 4:29 PM

    Hi Sarah,

     

    Please use 

    consolidatedInvoiceList = [SELECT  Total__c, Name FROM Consolidated_Invoicing__c Where Id =: ApexPages.currentPage().getParameters().get('id')];

    Here you can show the details of current record only. 

    I hope it helps you.

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

    Thanks and Regards,

    Biswojeet
Loading
0/9000