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
Mohammed Ikram 7Mohammed Ikram 7 

I want to Display all child invoices of a customer , I created a class controller

I want to Display all child invoices of a customer , I created a class controller,

public class ListOfChildRecordsInvoices
{

  

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

   
 
//List<Invoice__c> ListOfInvoices;

     public List<Invoice__c> getInvoices() {
         
        List<Customer__c> ListCustomers = [SELECT Name, Id, 
  (SELECT id, Name,Amount__c,Status__c FROM Invoice__r) FROM Customer__c WHERE Name = 'IBM'];
  
        if(ListOfInvoices == null)
         {
     List<Invoice__c> ListOfInvoices = ListCustomers[0].Invoice__r;
     }
     
     return ListOfInvoices;
   }
  
}

My visualForcepage is
 
<apex:page controller="ListOfChildRecordsInvoices" id="thePage">
    <apex:dataTable value="{!ListOfInvoices}" var="Stud" id="theTable"
        rowClasses="odd,even" styleClass="tableClass">
      
        <apex:facet name="caption">Invoices Details</apex:facet>
        <apex:facet name="header">Invoices data</apex:facet>
     <apex:facet name="footer">End Of Page</apex:facet>

         <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Name}"/>
        </apex:column>
    <apex:column >
            <apex:facet name="header">Amount</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Amount__c}"/>
        </apex:column>

        <apex:column >
            <apex:facet name="header">Email</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Status__c}"/>
        </apex:column>

        

    </apex:dataTable>
    </apex:page>

I am not getting the results , please help
 
Best Answer chosen by Mohammed Ikram 7
Rahul.MishraRahul.Mishra
Hi Ikram,

Your code is not working because controller does not return invoices, I have slightly modified the controller, please use the following code and let me know if it works:
public class ListOfChildRecordsInvoices
{    
    public List<Invoice__c> ListOfInvoices {get;set;} 
    public ListOfChildRecordsInvoices () {
        ListOfInvoices = new List<Invoice__c>();
        
        List<Customer__c> ListCustomers = [SELECT Name, Id,(Select Id,Name,Amount__c,Status__c FROM Invoice__r From Invoice__r) FROM Customer__c WHERE Name = 'IBM'];
        
        if(ListOfInvoices.isEmpty())
        {
            ListOfInvoices = ListCustomers[0].Invoice__r;
        }
        system.debug('ListOfInvoices is '+ListOfInvoices);
    }
}

Mark my answer best if it does help you.


Thanks,
Rahul

All Answers

Rahul.MishraRahul.Mishra
Hi Ikram,

Your code is not working because controller does not return invoices, I have slightly modified the controller, please use the following code and let me know if it works:
public class ListOfChildRecordsInvoices
{    
    public List<Invoice__c> ListOfInvoices {get;set;} 
    public ListOfChildRecordsInvoices () {
        ListOfInvoices = new List<Invoice__c>();
        
        List<Customer__c> ListCustomers = [SELECT Name, Id,(Select Id,Name,Amount__c,Status__c FROM Invoice__r From Invoice__r) FROM Customer__c WHERE Name = 'IBM'];
        
        if(ListOfInvoices.isEmpty())
        {
            ListOfInvoices = ListCustomers[0].Invoice__r;
        }
        system.debug('ListOfInvoices is '+ListOfInvoices);
    }
}

Mark my answer best if it does help you.


Thanks,
Rahul
This was selected as the best answer
Mohammed Ikram 7Mohammed Ikram 7
Thanks Rahul,

I am new to Salesforce. This really helped me.

Thanks Again. Thank you very very much.

Can you please also let me know how to pass the value from visualforce page field and get the result from the class.
Sample code will help me. 
Mohammed Ikram 7Mohammed Ikram 7
Hi Rahul,

Adding a query for my previous question.

I want to display the Customer Name and well as Address, from the class we can get it by
system.debug('ListOfCustomers is '+ListCustomers[0].Name);
system.debug('ListOfCustomers is '+ListCustomers[0].Address__c);

But how to return that, so that we can display that in the VFpage.

 
public class ListOfChildRecordsInvoices
{

  

 public List<Invoice__c> ListOfInvoices {get;set;} 
    public ListOfChildRecordsInvoices () {
        ListOfInvoices = new List<Invoice__c>();
        
        List<Customer__c> ListCustomers = [SELECT Name, Id,(Select Id,Name,Amount__c,Status__c FROM Invoice__r ) FROM Customer__c WHERE Name = 'IBM'];
        
//system.debug('ListOfCustomers is '+ListCustomers[0].Address__c);

// want to retrun 'ListOfCustomers is '+ListCustomers[0].Address__c

        if(ListOfInvoices.isEmpty())
        {
            ListOfInvoices = ListCustomers[0].Invoice__r;
        }
        system.debug('ListOfInvoices is '+ListOfInvoices);
    }
    

    

}

Can you please also let me know how to pass the value from visualforce page field and get the result from the class.
Sample code will help me. 

Thanks in Advance.
Ikram
Rahul.MishraRahul.Mishra
Hi Ikram,

Below is the code for your requirement:
Class:

public class ListOfChildRecordsInvoices
{

    public List<Invoice__c> ListOfInvoices {get;set;} 
    public ListOfChildRecordsInvoices () {
	
        ListOfIvoices = new List<Invoice__c>();                
		ListOfInvoices = [Select Id,Name,Amount__c,Status__c,Customer__r.Name, Customer__r.Address__c FROM Invoice__c];

    }
}


Page:


<apex:page controller="ListOfChildRecordsInvoices" id="thePage">
    <apex:dataTable value="{!ListOfInvoices}" var="Stud" id="theTable"
        rowClasses="odd,even" styleClass="tableClass">
      
        <apex:facet name="caption">Invoices Details</apex:facet>
        <apex:facet name="header">Invoices data</apex:facet>
     <apex:facet name="footer">End Of Page</apex:facet>

         <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Name}"/>
        </apex:column>
    <apex:column >
            <apex:facet name="header">Amount</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Amount__c}"/>
        </apex:column>

        <apex:column >
            <apex:facet name="header">Email</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Status__c}"/>
        </apex:column>
		
		 <apex:column >
            <apex:facet name="header">Customer Name</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Customer__r.Name}"/>
        </apex:column>
		
		        <apex:column >
            <apex:facet name="header">Customer Address</apex:facet>
            <apex:facet name="footer">column footer</apex:facet>
            <apex:outputText value="{!Stud.Customer__r.Address__c}"/>
        </apex:column>

        

    </apex:dataTable>
    </apex:page>

 
Mohammed Ikram 7Mohammed Ikram 7

Hi Rahul,

Thanks for the help.

Can you please also let me know how to pass the value from visualforce page field and get the result from the class.
Sample code will help me. 

Thanks
Mohammed Ikram 7Mohammed Ikram 7
Hi Rahul,

Are you located in India?
Share your email and Phone no , if you have no problem, we can be in touch for any help.

my email is ikrammohiuddin@gmail.com (mailto:ikrammohiuddin@gmail.com)
Thanks
Ikram
Rahul.MishraRahul.Mishra
Hi Ikram,

I work in Bengalore,now a days I am onsite (Malasiya). You can any time what's app me on my number +9741717420 or email me on my rmail: rhlmishra782@gmail.com