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
NANCY1NANCY1 

How to get related records displayed on VF page??

Hi All,

 

 

On the Proposal__c object page i have two lookup fields.. one for Resource_Requirement__c object and another for  RR__c object. while creating the new proposal as i'll select the value for Resource_Requirement__c object.. using the lookup field..i should be able to view all the RR__c records related to selected value of Resource_Requirement__c on the visualforce page.... 

 

 

public class AllRRs
{
    private Resource_Requirement__c rrdetail;
    public List<RR__c> propdetail;
       
    public AllRRs(ApexPages.StandardController controller)
    {
        rrdetail=(Resource_Requirement__c)controller.getre​cord();
        propdetail = new List<RR__c>();
        RR__c rrlist = new RR__c();
        rrlist.RRF__c = rrdetail.id;
        propdetail.add(rrlist);                        
    }
   
    public RR__c[] getCaseRecords()
    {
        RR__c[] rrdetail = [select id,name,gPAC__c,RRF__c,Long_Term_Resource_Location​__c,Priority__c,Required_Skill__c,RR_Status__c,RM_​Phase__c from RR__c where RRF__c =:rrdetail.id];
        return rrdetail;
    }
}

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

To remove this error you need to query all fields including ( "Proposal_RRF__c" ) after you fetch record from standard controller.

 

Just put all fields that you are using in your controller like this :

 

public AllRRs(ApexPages.StandardController controller)
    {
        rrdetail=(Proposal__c)controller.getrecord();
//Select all field that you are using on visualforce and in controller
rrdetail = [select id,name,Proposal_RRF__c from Proposal__c where id =: rrdetail.Id] ;

        propdetail = new List<RR__c>();
        RR__c rrlist = new RR__c();
        rrlist.RRF__c = rrdetail.Proposal_RRF__c;
        propdetail.add(rrlist);                        
    }

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

cloudcodercloudcoder

You probably want to return either a custom Apex class, or multi-dimension collection back to your Visualforce page, or better still, if your data model already supports relationships (case records are associated with Proposals) you can return Proposal objects with nested cases.

NANCY1NANCY1

Hi Quinton,

 

yes, RR has a lookup relationship with Proposals... but to create proposals.. RR should belongs to another lookup field RRF..

 

i mean while creating the proposal.. i need to select that RRF and based on the selected RRF, RR should get displayed..assuming that i have tried changing the code now... but againg its not working and giving me the following error:

 

Error on the visualforce page:

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Proposal__c.Proposal_RRF__c

 

public class AllRRs
{
    private Proposal__c rrdetail;
    public List<RR__c> propdetail;
       
    public AllRRs(ApexPages.StandardController controller)
    {
        rrdetail=(Proposal__c)controller.getrecord();
        propdetail = new List<RR__c>();
        RR__c rrlist = new RR__c();
        rrlist.RRF__c = rrdetail.Proposal_RRF__c;
        propdetail.add(rrlist);                        
    }
   
    public RR__c[] getCaseRecords()
    {
        RR__c[] rrdetail = [select id,name,gPAC__c,RRF__c,Long_Term_Resource_Location__c,Priority__c,Required_Skill__c,RR_Status__c,RM_Phase__c from RR__c where RRF__c =:rrdetail.id];
        return rrdetail;
    }

 

VF Page:

<apex:page StandardController="Proposal__c" extensions="AllRRs">
<apex:pageBlock title="RRs related to RRF">
   </apex:pageBlock>
   <apex:pageBlock title="RRs">
      <apex:pageBlockTable value="{!CaseRecords}" var="temp">
         <apex:column value="{!temp.Name}"/>
         <apex:column value="{!temp.Long_Term_Resource_Location__c}"/>
         <apex:column value="{!temp.Priority__c}"/>
         <apex:column value="{!temp.Required_Skill__c}"/>
         <apex:column value="{!temp.RR_Status__c}"/>
         <apex:column value="{!temp.gPAC__c}"/>
         <apex:column value="{!temp.RM_Phase__c}"/>

               </apex:pageBlockTable>
   </apex:pageBlock>

 

</apex:page>

 

Ankit AroraAnkit Arora

To remove this error you need to query all fields including ( "Proposal_RRF__c" ) after you fetch record from standard controller.

 

Just put all fields that you are using in your controller like this :

 

public AllRRs(ApexPages.StandardController controller)
    {
        rrdetail=(Proposal__c)controller.getrecord();
//Select all field that you are using on visualforce and in controller
rrdetail = [select id,name,Proposal_RRF__c from Proposal__c where id =: rrdetail.Id] ;

        propdetail = new List<RR__c>();
        RR__c rrlist = new RR__c();
        rrlist.RRF__c = rrdetail.Proposal_RRF__c;
        propdetail.add(rrlist);                        
    }

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
chandra2ravichandra2ravi

Use the following code. add the field in vf page and set the property visible none.

 

<apex:page StandardController="Proposal__c" extensions="AllRRs"><apex:pageBlock title="RRs related to RRF">   </apex:pageBlock>   <apex:pageBlock title="RRs">      <apex:pageBlockTable value="{!CaseRecords}" var="temp">         <apex:column value="{!temp.Name}"/>         <apex:column value="{!temp.Long_Term_Resource_Location__c}"/>         <apex:column value="{!temp.Priority__c}"/>         <apex:column value="{!temp.Required_Skill__c}"/>         <apex:column value="{!temp.RR_Status__c}"/>         <apex:column value="{!temp.gPAC__c}"/>         <apex:column value="{!temp.RM_Phase__c}"/><apex:column style="display:none;" value="{!temp.Proposal_RRF__c}"/>               </apex:pageBlockTable>   </apex:pageBlock> </apex:page>

cloudcodercloudcoder

Let's step back a little here. First of all, if you are using a StandardController, you will have access to all the fields already. I would suggest using a controller extension to leverage this 'native' functionality and extend only what you need.

 

No need to re-invent the wheel if you don't have to.

 

NANCY1NANCY1

Many thanks that worked..

 

also, please suggest know how can i select the any particular record from the VF Page and update a particular field on the Proposal__c object page...

 

Thanks

sfdcChi2sfdcChi2
needed this