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
John SmithJohn Smith 

Filtering the Related List(Child Object fields) on parent obj layout

 

<apex:page standardController="Contact" extensions="CandidateController"  >
    <apex:form >
        <apex:pageBlock >
             <apex:pageBlockTable value="{!Data}" var="c">
               
                 <apex:column headerValue="Name" value="{!c.Candidatename}"> </apex:column>  
                 <apex:column headerValue="Candidate Stage" value="{!c.Candidatestage}"  />
                 <apex:column headerValue="Status" value="{!c.status}" />
                 <apex:column headerValue="Approval Status" value="{!c.contactname}" />
             </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
   	
</apex:page>

 

public with sharing class CandidateController {
    
    public Contact contacts;
    public List<TimeVO> myList {get; set;}
    public  List<Contact> cont = new List<contact>();
    public TimeVO temp {get;set;}
    
    public CandidateController(apexpages.standardcontroller controller) {
        contacts = (Contact) controller.getRecord();
        
    }
    
    

    public class TimeVO {
     	public String Candidatename{get;set;}
        public Date PSactualdate {get;set;}
        public Date PSSceduledate {get;set;}
        public String Candidatestage{get;set;}
        public String status{get;set;}
        public String Contactname{get;set;}
        
            
    }
  
 
    public List<TimeVO> makeData()
    
    {
       // TimeVO temp = new TimeVO();
        cont = [select id,Name From Contact];
        for(Contact c: cont)
        {
            temp.Contactname = c.Name;
            system.debug(c.Name);
        
        List<Candidate__c> cand = [select Name, candidate_stage__c,phone_screen_actual_date__c,phone_screen_scheduled_date__c from Candidate__c where contact__c =: c.id];
        
        for(candidate__c i: cand)
        {
        	system.debug(i.Name);
            temp.candidatename = i.Name;
            temp.Candidatestage = i.Candidate_Stage__c;
            temp.PSactualdate = i.phone_screen_actual_date__c;
            temp.PSSceduledate = i.phone_screen_scheduled_date__c;
            if(temp.Candidatestage == 'Phone Screen' && temp.PSSceduledate == NULL )
                {
                    temp.status = 'This is Phone screen actual date' + temp.PSactualdate + '';
                }
            if(temp.Candidatestage == 'Phone Screen' && temp.PSSceduledate != NULL)
                {
                    temp.status = 'Phone Screen scheduled date is  ' + temp.PSSceduledate + '';
                }
            
            
        }  
          
            myList.add(temp);  
        }
   
        	return myList;
        }
        
          public List<TimeVO> getData()
   	{
   	return myList;
   }
    
    }

 

I'm trying to display the child object fields(filtered) on the parent object layout.

I've developed a controller class where I'm writing the business logic, and then displaying the VF page on the top of parent object layout by editing the "View" with Visual force page and adding detail tag to the VF page.

The problem I'm facing is I couldn't the populate the pageblock table with the List I've generated. The table is displayed empty. I might be missing small thing, could you please let me know about the mistake. I'm attaching the code and screenshot of VF page.

In this case, parent object:contact Child obj: candidate relationship: candidates_r

bob_buzzardbob_buzzard

It looks to me like you are using the makeData method to construct the list, but I can't see anywhere in your code or page that you are executing it. Should this method be executed if the list is uninitialised?  Something like:

 

 

   public List<TimeVO> getData()
   {
        if (null==myList)
        {
           makeData();
        }
   	return myList;
   }

 

 

John SmithJohn Smith
I've tried it. An error os showing up when MyList is returned. Error: System.NullPointerException: Attempt to de-reference a null object Class.CandidateController.makeData: line 58, column 13 Class.CandidateController.getData: line 68, column 15 External entry point
bob_buzzardbob_buzzard

Its probably because this line is commented out:

 

 

 // TimeVO temp = new TimeVO();

 

So temp isn't initialised anywhere and thus is null.

 

John SmithJohn Smith
Have initialized the Temp variable in the initial part of controller with getter and setter.
bob_buzzardbob_buzzard

According to your original code, you haven't initialised it, you have just declared it, so it will have the default value of null and when you try to dereference it you will receive this error.