0

I've Assessment object is Parent and outcome object is Child. I'm displaying the assessment recrod in page block table and when I click on assessment record I've to display the related outcome(child) records.

As per requiremnt I'm using the Id of assesment record in the browser URL of Page. like ?id= a1G29000000lpk8

I've implemented the logic for my requirement but it is not wokrinig as expected.

When i click on the assesment record it always passing the id which is avaialbe in URL, not passing the id of record on which I clicked.

VF page.

<apex:page standardController="Assessment__c" sidebar="false" showHeader="false" extensions="cntr1test">

<apex:form >
<apex:pageBlock >
       <apex:pageBlockSection title="Outcome" id="Outcomed" columns="1" collapsible="true">
            <apex:pageBlockTable value="{!Asses}" var="b">
                <apex:column headerValue="Last Screening">
                    <apex:commandLink action="{!OutcomeList}" reRender="outpnl" >
                    <apex:outputField value="{!b.id}" />
                           <apex:param name="id" assignTo="{!asmntID}" value="{!b.id}"/>
                    </apex:commandLink>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
  </apex:pageBlock>
</apex:form>    

<apex:pageBlock id="collapseSec">
    <apex:pageBlockSection title="Outcomes" id="d" columns="1" collapsible="true">
            <apex:outputPanel id="outpnl" >
               <apex:pageBlockTable value="{!relatedout}" var="c" rendered="{!showoutcome}" >
                   <apex:column headerValue="Id" value="{!c.id}"/>
                   <apex:column headerValue="firstname" value="{!c.Name}"/>

               </apex:pageBlockTable>
           </apex:outputPanel>
    </apex:pageBlockSection>
</apex:pageBlock>    

Controller

public with sharing class cntr1test {

private List<Assessment__c> asses;
Assessment__c assment;
Assessment__c AssRec;
public ID asmntID{get;set;} 
public Outcome__c outcome{get;set;}

public cntr1test(ApexPages.StandardController controller) {
    this.assment= (Assessment__c)controller.getRecord();
    outcome = new Outcome__c ();
//here is query to fetch the record bases of the Id present in the URL 
//I'm using fields in this query in further part of logic. 
    AssRec= [select id,Name,Patient__r.Name from Assessment__c where Id=:assment.Id]; 
}

public List<Assessment__c> getAsses()
{
    asses = [Select id,Assessment_Description__c,Last_Screening__c,Date_Due__c, Resolved__c,Delete__c,Type__c,Sort__c,RT_Type__c,Outcome_Count__c,Create_Outcome__c from Assessment__c where Resolved__c=false];
    return asses;
}

public List<Outcome__c> relatedout{get;set;} 
public boolean showoutcome{get;set;}
public void OutcomeList(){
    system.debug('@@@'+asmntID); 
    relatedout = [Select id,Name from Outcome__c where Assessment_Number__c=:asmntID];
    system.debug('@@@'+relatedout);
    showoutcome=relatedout.size()>0?true:false;
}
}
  • which id is coming in system.debug ? – NITHESH K Nov 2 '17 at 7:35
  • @NITHESHK Id available in the browser URL. ?id= a1G29000000lpk8 – Amol Nov 2 '17 at 7:39
  • are you able to get assessment__c object when pageload or Outcome__c (relatedout ) is not getting load ? – NITHESH K Nov 2 '17 at 7:40
  • @NITHESHK yes. I'm getting assesment object on page load. & after page load when i click on assesment record, I want to dispaly related outcome record. – Amol Nov 2 '17 at 7:42
  • system.debug('@@@'+asmntID); are you getting asmntID which you have click ? – NITHESH K Nov 2 '17 at 7:45
0

Can you replace with this code.few change i have made with form tag and commandlink.

 <apex:form >
    <apex:pageBlock >
           <apex:pageBlockSection title="Outcome" id="Outcomed" columns="1" collapsible="true">
                <apex:pageBlockTable value="{!Asses}" var="b">
                    <apex:column headerValue="Last Screening">
                        <apex:commandLink action="{!OutcomeList}" reRender="collapseSec" value="{!b.id}" >
                               <apex:param name="id" assignTo="{!asmntID}" value="{!b.id}"/>
                        </apex:commandLink>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
      </apex:pageBlock>

    <apex:pageBlock id="collapseSec">
        <apex:pageBlockSection title="Outcomes" id="d" columns="1" collapsible="true">
                <apex:outputPanel id="outpnl" >
                   <apex:pageBlockTable value="{!relatedout}" var="c" rendered="{!showoutcome}" >
                       <apex:column headerValue="Id" value="{!c.id}"/>
                       <apex:column headerValue="firstname" value="{!c.Name}"/>
                   </apex:pageBlockTable>
               </apex:outputPanel>
        </apex:pageBlockSection>
    </apex:pageBlock>  
    </apex:form> 
| improve this answer | |
  • I've tried your code, but same issue. for this link https://c.ap7.visual.force.com/apex/demo it is working perfect and for this link https://c.ap7.visual.force.com/apex/account_contact_related?id=a1G29000000lolp not working expected. – Amol Nov 2 '17 at 8:35
  • if i am not wrong understood your question, You are passing assessment id in the url, and display the assessment__c object of related id. When you click on the assessment__c.id , Your are displaying all list of Outcome__c which is related assessment__c.id. right ? everything isfine according to your code. what problem again your facing ? , when your passing different assessment__c.id your are not able to display all list of Outcome__c ? – NITHESH K Nov 2 '17 at 8:56
  • 1
    it slightly different as per you understanding, by the way I've copied another code and it worked. Not sure whats wrong, I will find out in extra time. – Amol Nov 3 '17 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.