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
Abhiman MungalAbhiman Mungal 

i want all records from object

<apex:page standardController="Profile__c" extensions="OrdersFromUsers">
 <apex:outputPanel id="all">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockSection title="Orders" columns="1" >
        <apex:pageBlockTable value="{!OrdersFromUsers}" var="cont">
          <apex:column value="{!cont.Name}"/>
           <apex:column value="{!cont.Address__c}"/>
         <apex:column value="{!cont.Booking_Date__c}"/>
          <apex:column value="{!cont.Customer_Name__c}" />
          <apex:column value="{!cont.Event_Name__c}" />
          <apex:column value="{!cont.Event_Type__c}"/>
       <!--   <apex:column value="{!cont.Location__c}"/>-->
          <apex:column value="{!cont.Services__c}"/>
           <apex:column value="{!cont.Time__c}"/>
        </apex:pageBlockTable>
         </apex:pageBlockSection>
    </apex:pageBlock>
    
     <apex:pageBlock >
     
      <apex:pageBlockSection title="Customer Information" columns="1" id="info">
        <apex:pageBlockTable value="{!ViewCustomerDetail}" var="cust">
          
          <apex:column value="{!cust.Name}"/>
          <apex:column value="{!cust.Address__c}"/>
          <apex:column value="{!cust.District__c}"/>
          <apex:column value="{!cust.Email__c}" />
          <apex:column value="{!cust.Mobile_No__c}"/>
          <apex:column value="{!cust.Pin_Code__c}"/>
          <apex:column value="{!cust.State__c}"/>
         
        </apex:pageBlockTable>
      
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
 </apex:outputPanel>
</apex:page>


public with sharing class OrdersFromUsers {
     public List<Order__c> OrdersFromUsers{get; set;}
   public List<Profile__c> ViewCustomerDetail{get;set;}
   public String actualName;
    public OrdersFromUsers(ApexPages.StandardController controller) {
    
        List <Order__c> val=[select Customer_Name__c from Order__c where customerName__r.name=:UserInfo.getFirstName()+' '+UserInfo.getLastName()];
        for(integer i=0;i<val.size();i++)
        {
            actualName='%'+val[i].Customer_Name__c+'%';
            ViewCustomerDetail=[select name,Address__c,District__c,Email__c,Mobile_No__c,Pin_Code__c,State__c from Profile__c where name like:actualName];
            
        }
        actualName='';
       OrdersFromUsers=[select name,Address__c,Booking_Date__c,Customer_Name__c,Event_Name__c,Event_Type__c,Services__c,Time__c from Order__c where customerName__r.name=:UserInfo.getName()];
    }
 
}

if i do this its giving me last record of that list but i want all records from this list
so what can i do plz tell me....
Best Answer chosen by Abhiman Mungal
Sohan Raj GuptaSohan Raj Gupta
Hi Abhiman,

We have not initialize the ViewCustomerDetail in constructor, so you need to add below line at line number 6

ViewCustomerDetail = new List<Profile__c>();

You can use below sample code:
public with sharing class OrdersFromUsers {
     public List<Order__c> OrdersFromUsers{get; set;}
   public List<Profile__c> ViewCustomerDetail{get;set;}
   public String actualName;
    public OrdersFromUsers(ApexPages.StandardController controller) {
        ViewCustomerDetail = new List<Profile__c>();
List<Profile__c> ViewCustomerDetailTemp = new List<Profile__c>();
        
        List <Order__c> val=[select Customer_Name__c from Order__c where customerName__r.name=:UserInfo.getFirstName()+' '+UserInfo.getLastName()];
        for(integer i=0;i<val.size();i++)
        {
            ViewCustomerDetailTemp = new List<Profile__c>();
            actualName='%'+val[i].Customer_Name__c+'%';
            ViewCustomerDetailTemp =[select name,Address__c,District__c,Email__c,Mobile_No__c,Pin_Code__c,State__c from Profile__c where name like:actualName];
            ViewCustomerDetail.addAll(ViewCustomerDetailTemp);
        }
        actualName='';
       OrdersFromUsers=[select name,Address__c,Booking_Date__c,Customer_Name__c,Event_Name__c,Event_Type__c,Services__c,Time__c from Order__c where customerName__r.name=:UserInfo.getName()];
    }
 
}

 Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 

All Answers

Sohan Raj GuptaSohan Raj Gupta
Hi Abhiman,

As per your controller class you are overwriting ViewCustomerDetail varibale in for loop, that's why you are getting last record values.

Your code should be look like:
 
public with sharing class OrdersFromUsers {
     public List<Order__c> OrdersFromUsers{get; set;}
   public List<Profile__c> ViewCustomerDetail{get;set;}
   public String actualName;
    public OrdersFromUsers(ApexPages.StandardController controller) {
        List<Profile__c> ViewCustomerDetailTemp = new List<Profile__c>();
        
        List <Order__c> val=[select Customer_Name__c from Order__c where customerName__r.name=:UserInfo.getFirstName()+' '+UserInfo.getLastName()];
        for(integer i=0;i<val.size();i++)
        {
            ViewCustomerDetailTemp = new List<Profile__c>();
            actualName='%'+val[i].Customer_Name__c+'%';
            ViewCustomerDetailTemp =[select name,Address__c,District__c,Email__c,Mobile_No__c,Pin_Code__c,State__c from Profile__c where name like:actualName];
            ViewCustomerDetail.addAll(ViewCustomerDetailTemp);
        }
        actualName='';
       OrdersFromUsers=[select name,Address__c,Booking_Date__c,Customer_Name__c,Event_Name__c,Event_Type__c,Services__c,Time__c from Order__c where customerName__r.name=:UserInfo.getName()];
    }
 
}

Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
Abhiman MungalAbhiman Mungal
no its not working
its giving me an error like null pointer Exception
 
Sohan Raj GuptaSohan Raj Gupta
Hi Abhiman,

We have not initialize the ViewCustomerDetail in constructor, so you need to add below line at line number 6

ViewCustomerDetail = new List<Profile__c>();

You can use below sample code:
public with sharing class OrdersFromUsers {
     public List<Order__c> OrdersFromUsers{get; set;}
   public List<Profile__c> ViewCustomerDetail{get;set;}
   public String actualName;
    public OrdersFromUsers(ApexPages.StandardController controller) {
        ViewCustomerDetail = new List<Profile__c>();
List<Profile__c> ViewCustomerDetailTemp = new List<Profile__c>();
        
        List <Order__c> val=[select Customer_Name__c from Order__c where customerName__r.name=:UserInfo.getFirstName()+' '+UserInfo.getLastName()];
        for(integer i=0;i<val.size();i++)
        {
            ViewCustomerDetailTemp = new List<Profile__c>();
            actualName='%'+val[i].Customer_Name__c+'%';
            ViewCustomerDetailTemp =[select name,Address__c,District__c,Email__c,Mobile_No__c,Pin_Code__c,State__c from Profile__c where name like:actualName];
            ViewCustomerDetail.addAll(ViewCustomerDetailTemp);
        }
        actualName='';
       OrdersFromUsers=[select name,Address__c,Booking_Date__c,Customer_Name__c,Event_Name__c,Event_Type__c,Services__c,Time__c from Order__c where customerName__r.name=:UserInfo.getName()];
    }
 
}

 Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
This was selected as the best answer
Abhiman MungalAbhiman Mungal
thanks you so much
its working fine