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
DRobi83DRobi83 

Help with getID on visualforce page to return related records only

Hello Community

 

I am trying to use a class to draw records from a child of the parent, but im returning ALL the records for the object, just not those related to that recordID. My extensions should only return records that are related to the parentID. I believe it has something to do with my WHERE statement and getID but im very new. Thanks in advance

 

Here is my VF Page

 

<apex:page showHeader="false" standardController="miiProject__Project__c" extensions="OngoingCostsList,SetupCostsList,TaskList,MilestoneList">
<html>
<head>
  <style> 
     body {font-family: Arial Unicode MS;}
     .companyName {font-weight:bold;font-size:22px;color:red} 
     .projectplan {font-family: Arial, Helvetica, sans-serif;font-size: 22px;} 
     .projectdetails {font-family: Arial, Helvetica, sans-serif;font-size: 12px;} 
     .body {font-family: Arial, Helvetica, sans-serif;font-size: 10px; vertical-align:top; text-align:top; } 
     .total {font-family: Arial, Helvetica, sans-serif;font-size: 10px; vertical-align:middle; text-align:middle; } 
     .headerbackgroundblue {font-family: Arial, Helvetica, sans-serif;font-size: 12px;background-color:#003399;color: #FFFFFF;font-weight:bold;}
     .headerbackgroundgrey {font-family: Arial, Helvetica, sans-serif;font-size: 11px;background-color:#EFEFEF;color: #000000;font-weight:bold;}
     .headerbackgroundorange {font-family: Arial, Helvetica, sans-serif;font-size: 12px;background-color:#FFC993;color: #000000;font-weight:bold;}
     .headerbackgroundgreen {font-family: Arial, Helvetica, sans-serif;font-size: 12px;background-color:#DFFFE1;color: #000000;font-weight:bold;}
     .bordersolid {border:black solid 1px; font-family: Arial, Helvetica, sans-serif;font-size: 10px; vertical-align:middle; text-align:middle;  } 

@page {
    @bottom-center { content:"Page " counter(page) " - Commercial in Confidence - miiForce Pty Ltd | www.miiworks.com";
    margin-left: 3cm;
    margin-right: 3cm;
    font-family: Arial, Helvetica, sans-serif;font-size: 10px;
  }
      }
  </style>
</head>
<table width="100%" border="0" cellpadding="5">
  <tr>
    <td><div align="center">
    <apex:image value="{!$Resource.miiworks177120}" width="177" height="120"/></div></td>
  </tr>
  <tr>
    <td><div align="center" class="projectplan">Project Plan</div></td>
  </tr>
</table>
<br></br>
<table width="40%" border="0" align="center" cellpadding="5">
  <tr>
    <td class="body">Company:</td>
    <td class="body"><strong><apex:outputField value=" {!miiProject__Project__c.Account_Name_Text__c}"/></strong></td>
  </tr>
  <tr>
    <td class="body">Document Owner:</td>
    <td class="body"><strong>miiWorks Pty Ltd</strong></td>
  </tr>
  <tr>
    <td class="body">Start Date:</td>
    <td class="body"><strong><apex:outputField value="{!miiProject__Project__c.miiProject__Date_Project_Start__c}"/></strong></td>
  </tr>
  <tr>
    <td class="body">End Date:</td>
    <td class="body"><strong><apex:outputField value="{!miiProject__Project__c.miiProject__Date_Project_End__c}"/></strong></td>
  </tr>
  <tr>
    <td class="body">Version:</td>
    <td class="body"><strong><apex:outputField value="{!miiProject__Project__c.Version__c}"/></strong></td>
  </tr>  
</table>
<br></br>
<table width="40%" border="0" align="center" cellpadding="5">
  <tr>
    <td class="body">Summary:</td>
    <td class="body"><strong><apex:outputField value="{!miiProject__Project__c.miiProject__Subject__c}"/></strong></td>
  </tr>
  <tr>
    <td class="body">Description:</td>
    <td class="body"><apex:outputField value="{!miiProject__Project__c.miiProject__Description__c}"/></td>
  </tr>
</table>

<br></br><br></br>
    
   <apex:outputPanel >
<table border="1" cellpadding="5" width="75%" align="center" valign="top"> 
     <tr>
       <td class="headerbackgroundblue">AREA MANAGERS / RESPONSIBILITIES</td>
     </tr>  
    <apex:dataTable value="{!miiProject__Project__c.Project_Contacts__r}" var="c" cellpadding="5" border="1" width="75%" rows="4" align="center">
       <apex:column headerClass="headerbackgroundgrey" headerValue="Name" value="{!c.Contact_Text__c}" width="100px" styleClass="body" />
       <apex:column headerClass="headerbackgroundgrey" headerValue="Company" value="{!c.Account_Name__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Role" value="{!c.Role__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Responsibilities" value="{!c.Responsibilities__c}" styleClass="body" />
    </apex:dataTable>
</table> 
&nbsp;
   <table border="1" cellpadding="5" width="75%" align="center">
     <tr>
       <td class="headerbackgroundblue">GUIDELINES</td>
     </tr>
     <tr>
       <td styleClass="body"><br></br>
         <strong class="body">1. EXECUTION OF  MILESTONES</strong><br></br>
         <span class="body">The project execution must be  completed in the explicit order of the milestones to achieve project success.</span>
         &nbsp;<br></br><br></br>
         <strong class="body">2. OVERDUE TASKS</strong><br></br>
         <span class="body">If a task falls overdue, the person responsible  for the task should make every effort to complete the task in a timely manner  or propose a new completion date to the project team members.</span>
         &nbsp;<br></br><br></br>
         <strong class="body">3. PROJECT FAILURE</strong><br></br>
         <span class="body">If a milestone has not been reached  by its due date due to one or many overdue tasks, the project will fall into  alert status and a priority team meeting will be called to discuss the  milestone and overdue tasks.</span>
         &nbsp;<br></br>
         <span class="body">
         The project manager reserves the  right to re-allocate the task to another team member to complete the task or  freeze the project if there is a lack of commitment and/or resources from the  team member.</span>
         &nbsp;<br></br><br></br>
         <strong class="body">4. LOCALE</strong><br></br>
         <span class="body">Please take note:</span>
         <p><ul>
           <span class="body">Date Format: dd/mm/yy (please note that long  date format may be used)</span>
         </ul>
         <ul>
           <span class="body">Language of Document: English (British)</span>
         </ul></p>
           <strong class="body">5. TERMINOLOGY</strong><br></br>
           <span class="body">UAT – User Acceptance  Testing</span></td>
     </tr>
   </table>
   <br></br>
   </apex:outputPanel> 
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundblue">MILESTONES</td>
     </tr>  
 <apex:dataTable value="{!MilestoneList}" var="m" cellpadding="5" border="1" width="75%" align="center">
       <apex:column headerClass="headerbackgroundgrey" headerValue="Milestone" value="{!m.miiProject__Subject__c}" styleClass="body"/> 
       <apex:column headerClass="headerbackgroundgrey" width="65px" headerValue="Due Date" value="{!m.miiProject__Date_Due__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" width="90px" headerValue="Signed Off Date" value="{!m.Date_Signed_Off__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" width="90px" headerValue="Completed Date" value="{!m.miiProject__Date_Time_Completed__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" width="65px" headerValue="Signed Off?" styleClass="body" >
       <apex:outputText value="{!m.Signed_Off__c}" escape="false"/>
       </apex:column>
   </apex:dataTable>
</table>
<br></br>
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundblue">TASKS</td>
     </tr>
 <apex:dataTable value="{!TaskList}" var="t" cellpadding="5" border="1" width="75%" align="center">
       <apex:column headerClass="headerbackgroundgrey" headerValue="Milestone" value="{!t.Milestone_Subject__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Task" value="{!t.miiProject__Subject__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Detail">
           <apex:outputText value="{!t.miiProject__Description__c}" style="body" styleClass="body" escape="false"/>
       </apex:column>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Who" value="{!t.Assigned_To_Text__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" width="65px" headerValue="Due Date" value="{!t.miiProject__Date_Due__c}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Status" styleClass="body">
       <apex:outputText value="{!t.Status_Image__c}" escape="false"/>
       </apex:column>
 </apex:dataTable>
</table> 
<br></br>
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundblue">RISK/ENHACEMENT ANALYSIS LOG</td>
     </tr>  
   <apex:dataTable value="{!miiProject__Project__c.Project_Risks_Enhancments__r}" var="ri" cellpadding="5" border="1" width="75%" align="center" >            
       <apex:column headerClass="headerbackgroundgrey" headerValue="ID" value="{!ri.Name}" styleClass="body"/>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Nature" value="{!ri.Subject__c}" styleClass="body"/>  
       <apex:column headerClass="headerbackgroundgrey" headerValue="Description Of Requirements" value="{!ri.Description__c}" styleClass="body"/>  
       <apex:column headerClass="headerbackgroundgrey" headerValue="Status" value="{!ri.Status__c}" styleClass="body"/>
   </apex:dataTable>  
</table> 
<br></br>
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundblue">APPENDICES</td>
     </tr>  
   <apex:dataTable value="{!miiProject__Project__c.Project_Appendixs__r}" var="ap" cellpadding="5" border="1" width="75%" align="center" >            
       <tr>
       <apex:column headerClass="headerbackgroundgrey" headerValue="ID" value="{!ap.Name} - {!ap.Subject__c}" styleClass="body"/><br></br>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Description" value="{!ap.Description__c}" styleClass="body"/>  
       </tr>
   </apex:dataTable>  
</table>
<br></br>
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundorange">SETUP COSTS</td>
     </tr>  
   <apex:dataTable value="{!SetupCostsList}" var="cose" cellpadding="5" border="1" width="75%" align="center" >            
       <tr>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Description" value="{!cose.Description__c}" styleClass="body"/>  
       <apex:column width="90" headerClass="headerbackgroundgrey" headerValue="Cost Per Hour" value="{!cose.Amount_Per_Hour__c}" styleClass="body"/>  
       <apex:column width="90" headerClass="headerbackgroundgrey" headerValue="Hour(s)" value="{!cose.Hours__c}" styleClass="body"/> 
       <apex:column width="90" headerClass="headerbackgroundgrey" headerValue="Setup Cost" value="{!cose.Cost_Total__c}" styleClass="body"/>   
       </tr> 
   </apex:dataTable> 
   <table cellpadding="5" width="75%" align="center">
       <td valign="top" styleClass="body"><img src="https://ap1.salesforce.com/resource/1330407794000/exclamation"></img><strong class="body">All Prices Exclude GST</strong></td>
       <td width="90" align="left"><strong class="total">Totals:</strong></td>
       <td width="90" align="left" class="bordersolid"><strong><apex:outputField value="{!miiProject__Project__c.Hours_Setup_Total__c}" styleClass="total"/></strong></td>
       <td width="90" align="left" class="bordersolid"><strong><apex:outputField value="{!miiProject__Project__c.Total_Costs_Setup__c}" styleClass="total"/></strong></td>
   </table>
</table> 
<br></br>
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundorange">ONGOING COSTS</td>
     </tr>  
   <apex:dataTable value="{!OngoingCostsList}" var="coon" cellpadding="5" border="1" width="75%" align="center">           
       <tr>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Product" value="{!coon.Product_Name__c}" styleClass="body"/><br></br>
       <apex:column headerClass="headerbackgroundgrey" headerValue="Description" value="{!coon.Description__c}" styleClass="body"/>
       <apex:column width="90" headerClass="headerbackgroundgrey" headerValue="# Users" value="{!coon.Number_Of_Users__c}" styleClass="body"/>  
       <apex:column width="90" headerClass="headerbackgroundgrey" headerValue="$ Per User" value="{!coon.Amount_Per_User__c}" styleClass="body"/>
       <apex:column width="90" headerClass="headerbackgroundgrey" headerValue="Total/Month" value="{!coon.Cost_Total__c}" styleClass="body"/>  
       </tr>
   </apex:dataTable>
   <table cellpadding="5" border="0" width="75%" align="center">
       <td valign="top" styleClass="body"><img src="https://ap1.salesforce.com/resource/1330407794000/exclamation"></img><strong class="body">All Prices Exclude GST</strong></td>
       <td width="90" align="left" styleClass="body"></td>
       <td width="90" align="left" styleClass="body"><strong class="total">Totals:</strong></td>
       <td width="90" align="left" class="bordersolid"><strong><apex:outputField value="{!miiProject__Project__c.Total_Costs_Ongoing__c}" styleClass="total"/></strong></td>
   </table> 
<br></br>
<table border="1" cellpadding="5" width="75%" align="center"> 
     <tr>
       <td class="headerbackgroundgreen"><img src="https://ap1.salesforce.com/resource/1330407553000/greentick"></img>ACCEPTANCE</td>
     </tr>    
     <tr>
       <td><br></br>
         <strong class="body">Project Plan Acceptance: I agree that the information above is a complete and accurate</strong><br></br><br></br>
         <span class="body">The project execution must be  completed in the explicit order of the milestones to achieve project success.</span><br>
         </br><br></br><br></br>
         <br></br>
         <strong class="body">Client Signature: ________________________________________</strong><br></br><br></br>
         <br></br><br></br>
         <strong class="body">Client Full Name: ________________________________________</strong><br></br><br></br>
         <br></br>
         <strong class="body">Client Company Name: <strong><apex:outputField value=" {!miiProject__Project__c.Account_Name_Text__c}"/></strong></strong><br></br><br></br>
         <br></br>
         <strong class="body">Date: ________________________________________</strong><br></br><br></br>       </td>  
     </tr>
   </table>  
</table>   
</html> 
</apex:page>

 

Here is 1 of my classes (I can make changes when i understand methadology)

 

public class TaskList {

    public TaskList(ApexPages.StandardController controller)

    {

    }

    List<miiProject__Project_Task__c> myList;

    Public List<miiProject__Project_Task__c> getTaskList() {

myList = [SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, miiProject__Project_Milestone__c, miiProject__Account_Name_ID__c, miiProject__Account_Name__c, miiProject__Active__c, miiProject__Actual_Hours__c, miiProject__Alert_Assigned_To__c, miiProject__Assigned_To_Client__c, miiProject__Assigned_To_Email__c, miiProject__Assigned_To__c, miiProject__Contact_Email__c, miiProject__Contact_Name__c, miiProject__Date_Due__c, miiProject__Date_Time_Completed__c, miiProject__Date_Time_Started__c, miiProject__Description__c, miiProject__Internal_Comments__c, miiProject__Is_Closed__c, miiProject__Project_Manager_Email__c, miiProject__Project_Manager_Name__c, miiProject__Public__c, miiProject__Status__c, miiProject__Subject__c, ID_Historic__c, Date_Created_Historic__c, Project__c, Milestone_Subject__c, Status_Image__c, Assigned_To_Text__c FROM miiProject__Project_Task__c ORDER BY miiProject__Date_Due__c ASC ];

    /// ORDER BY CAN BE ASC OR DESC 

    return  myList;

    }

    public static testmethod void Test1()

    {

    miiProject__Project_Task__c p=new miiProject__Project_Task__c();

    ApexPages.StandardController sc = new ApexPages.standardController(p);

           

    TaskList Tas=new TaskList (sc);

    Tas.getTaskList();

    }     

}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I can't see a where clause in your code, so I'm guessing that is what you are looking for help on.

 

First thing I'd do is save a reference to the standard controller for later use:

 

 private ApexPages.StandardController stdCtrl;

 public TaskList(ApexPages.StandardController controller)

 {
     stdCtrl=controller;
 }

 

Then you can use the id of the record that the controller is managing to restrict your query - something like:

 

...
FROM miiProject__Project_Task__c 
WHERE Project__c=:stdCtrl.getId()
ORDER BY miiProject__Date_Due__c ASC ];

 

 

All Answers

bob_buzzardbob_buzzard

I can't see a where clause in your code, so I'm guessing that is what you are looking for help on.

 

First thing I'd do is save a reference to the standard controller for later use:

 

 private ApexPages.StandardController stdCtrl;

 public TaskList(ApexPages.StandardController controller)

 {
     stdCtrl=controller;
 }

 

Then you can use the id of the record that the controller is managing to restrict your query - something like:

 

...
FROM miiProject__Project_Task__c 
WHERE Project__c=:stdCtrl.getId()
ORDER BY miiProject__Date_Due__c ASC ];

 

 

This was selected as the best answer
DRobi83DRobi83

Thank you very much, that worked