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
charlie_vcharlie_v 

Query Problem

Can someone please help me with this? 

 

I have 2 custom objects:  Headline__c, and Headline_Comments__c.

 

Headline__c is the 'master' in a Master-Detail relationship with Headline_Comments__c.

 

When viewing a headline record, I want to show all associated comments.  But I need to filter the related list to return only those comments where "Post_to_Site__c" equals TRUE.

 

Here's the controller:

 

public class HeadlineCommentsController { Public Headline__c[] getHeadline(){ return [SELECT Id, Name, Item__c FROM Headline__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')]; } Public Headline_Comment__c[] getHeadlineComments(){ return [SELECT Id, Name, Comment__c, Comment_Brief__c, Comment_By__c, Email__c, Post_to_Site__c FROM Headline_Comment__c WHERE Headline__r.ID = :ApexPages.currentPage().getParameters().get('id') AND Post_to_Site__c = True]; } }

 

Here's the VF page:

 

<apex:page Controller="HeadlineCommentsController"> <apex:pageBlock title="Comments" > <apex:repeat value="{!HeadlineComments}" var="each"> Posted by {!each.Comment_By__c} {!each.Comment__c} </apex:repeat> </apex:pageBlock> </apex:page>

 

The problem is, I can get the comments to show just fine, but when I try to expose any of the Headline fields in my VF page, something like

 

<apex:detail subject="{!Headline}" relatedList="false"> </apex:detail>

 

I keep getting the following error:

 

Insufficient Privileges You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.
 

I've checked all the security, and as the Admin I should have access to the VF Page, all the Objects, all the Fields, and the Apex class.

 

Can someone please point me in the right direction?  I'm not a coder by trade, so code samples would be appreciated.

 

Thank you.

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
charlie_vcharlie_v

Wow, I was approaching this all wrong.  There is a much more simple way to do this, and it doesn't even require a custom controller.

 

 

<apex:page standardController="Headline__c" > <apex:outputField value="{!Headline__c.Name}"/> <br /><br /> <apex:repeat value="{!Headline__c.Headline_Comments__r}" var="hc"> <apex:outputPanel rendered="{!hc.Post_to_Site__c}"> {!hc.Comment__c} <br /><br /> </apex:outputPanel> </apex:repeat> </apex:page>

 

 Being able to conditionally render an ouputPanel is extremely powerful. 

<apex:outputPanel rendered="{!hc.Post_to_Site__c}">

 

Post_to_Site is a checkbox field, and calling it in the rendered attribute turned out to be the answer.

 

I still don't know what was causing the "Insufficient Privileges" message I was getting, but it's no longer an issue.