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
Lars SundbergLars Sundberg 

Looking up a subset of data in a controller

I'm trying to figure out how to look up the names of all users who has access to a certain record, and display those for each record on a VF page.


Ideally, I want to get that data directly in the getNoteList method. But then I can't return the results as a Note__c object.


The other option is to use the getRecipientList method, but then I need to pass a parameter to it (like the Id of the Note__c object), and I can't do that without using a button, can I?


This is what I have so far:


VisualForce page:


<apex:page controller="NoteboardController">
        <apex:repeat value="{!noteList}" var="n" rendered="{!$ObjectType.Note__c.accessible}">
                <b>From: </b><apex:outputText value="{!n.owner.Name}"/><br/>
                <b>To: </b>
                    <apex:repeat value="{!recipientList}" var="r">
                        <apex:outputText value="{!r.Name}"/>
                <apex:outputText value="{!n.Name}"/><br/><br/>
                <apex:outputText value="{!n.Note_body__c}"/>
        <apex:outputText value="You don't have access the Note object" rendered="NOT({!$ObjectType.Note__c.accessible})"/>




public with sharing class NoteboardController {
    public NoteboardController() {
    public Note__c[] getNoteList() {
        Note__c [] noteList;
        noteList = [SELECT Id, Name, Note_body__c, owner.Name FROM Note__c];
        return noteList;
    public User[] getRecipientList() {
        //Get the name of THE FIRST user who has access to THE FIRST of the displayed Notes
        Note__c [] noteList;
        noteList = [SELECT Id, Name, Note_body__c, owner.Name FROM Note__c];
        Note__Share [] noteShare;
        noteShare = [SELECT UserOrGroupId FROM Note__Share WHERE ParentId = :noteList[0].Id];
        User [] recipientList;
        recipientList = [SELECT Name FROM User WHERE Id = :noteShare[0].UserOrGroupId];
        return recipientList;
        //Get the names of ALL users who has access to the displayed Notes
        //User [] recipientList;
        //recipientList = [SELECT Name FROM User WHERE Id IN (SELECT UserOrGroupId FROM Note__Share)];
        //return recipientList;