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
CushtyCushty 

Display related list in visualforce

Hi,

I am trying to write the visualforce to display a related list.  I have a custom object User_Stories__c and a child object Votes__c. The master detail field is called User_Story__c.
 am trying to display all the votes__c records per User Story (the same as a normal related list without the del and edit actions)
I have managed to get the code for the page but the controller logic linking the record together I am struggling with

controller code: -

public class Voters {

    public List<User_Stories__c> story{get;set;}
    public Voters(ApexPages.StandardController standardController)
    {
    
      string story= [SELECT Name, Voted__c FROM Votes__c WHERE id=:Apexpages.currentpage().getparameters().get('id')].User_Story__c      
    }
 }

help!

Nick
 
Srinath TerampattilSrinath Terampattil
Hey Nick,

You need not write a custom controller just to show this. You can leverage the standard controller functionality for acheiving this.
<apex:relatedList list="Votes__c"> <!-- Write the child relationship name here --> 
                          <apex:facet name="header">Titles can be overriden with facets</apex:facet>
/apex:relatedList>

For more details, please refer this documentation - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_relatedList.htm

Thanks
Srinath
CushtyCushty
Hi,

I have a master custom object called User_Stories__c
Child Object called Votes__c

this object is basically where users can log their ideas and the votes object is where people vote on the idea.  I want toshow the related list showing the people whom have voted.  I can show just the standard related list but I want it to show just the list of names minus the action column!

I want to write the visualforce to show all the child records per master record.  The master-detail lookup field is User_Story__c

heres what I have as my controller so far: -
public class names {

Public id votesID;

    public names(ApexPages.StandardController controller) {
    votesID= controller.getRecord().id;
    }

    public List<Votes__c> getrelatedvotes(){
        List <Votes__c> votList = New List<Votes__c>();
        for(Votes__c ustory:[select id,name,(select name,id,Voted__c from Votes__r) from User_Stories__c where id=:votesID]){
           for(Votes__c vot:ustory.Voted__c)
               votList.add(vot); 
        }
        return votList;
    }
}

I get the following eror Loop must iterate over a collection type: Id at line 12 column 29 and as I am new to visualforce, qite lost

Hope you can help

nick