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
FreeFree 

Filter Data of a Related List

Hi all,
I'm new to VisualForce but have been told this might be the solution to my issue.
 
What I'm trying to achieve is pretty simple :
- Some users are allowed to see only certain types of Activities (which are identified through a custom checkbox called isPublic__c)
- I am thus trying to create a VisualForce page for cases that would filter the Activities related list based on that checkbox (isPublic__c == true).
 
Do I need to create a custom/extended controller for that ?
I yes, do you have any sample code that would achieve this ?
 
Thanks for your help that would greatly be apreciated...
Best Answer chosen by Admin (Salesforce Developers) 
MVJMVJ
This should get you started.  you will need to modfiy the controller to return the datathat you want to display and add in your selection criteria.

The Page looks like this:

Code:
<apex:page Controller="ActivityController" tabstyle="Account">

    <apex:detail subject="{!account}" relatedlist="False">
    </apex:detail>

    <apex:pageBlock title="Activities" >
    <apex:pageBlockSection title="Activities I have access to" columns="1" collapsible="true">
    <apex:dataTable value="{!Activities}" var="each" cellpadding="10" border="0" styleClass="list">
        <apex:column headerValue="Id"><a href="/{!each.Id}">{!each.Id}</a></apex:column>  
    </apex:dataTable>
    </apex:pageBlockSection>
    </apex:pageBlock>

</apex:page>

 The controller looks like this:


Code:
public class ActivityController {
        Public Task[] getActivities(){
                return [Select id from Task where accountid = :System.currentPageReference().getParameters().get('id') and  isClosed = false];
        }

        Public Account getAccount(){
                return [Select id, name, Owner.Name, Site, BillingStreet, BillingCity, BillingState, BillingPostalCode
                        from Account where id = :System.currentPageReference().getParameters().get('id')];

        }
}

 
Check out the VF Documentation http://www.salesforce.com/us/developer/docs/pages/index.htm



All Answers

MVJMVJ
This should get you started.  you will need to modfiy the controller to return the datathat you want to display and add in your selection criteria.

The Page looks like this:

Code:
<apex:page Controller="ActivityController" tabstyle="Account">

    <apex:detail subject="{!account}" relatedlist="False">
    </apex:detail>

    <apex:pageBlock title="Activities" >
    <apex:pageBlockSection title="Activities I have access to" columns="1" collapsible="true">
    <apex:dataTable value="{!Activities}" var="each" cellpadding="10" border="0" styleClass="list">
        <apex:column headerValue="Id"><a href="/{!each.Id}">{!each.Id}</a></apex:column>  
    </apex:dataTable>
    </apex:pageBlockSection>
    </apex:pageBlock>

</apex:page>

 The controller looks like this:


Code:
public class ActivityController {
        Public Task[] getActivities(){
                return [Select id from Task where accountid = :System.currentPageReference().getParameters().get('id') and  isClosed = false];
        }

        Public Account getAccount(){
                return [Select id, name, Owner.Name, Site, BillingStreet, BillingCity, BillingState, BillingPostalCode
                        from Account where id = :System.currentPageReference().getParameters().get('id')];

        }
}

 
Check out the VF Documentation http://www.salesforce.com/us/developer/docs/pages/index.htm



This was selected as the best answer
FreeFree
MVJ you just saved my day, thanks a million. I will try this tomorrow (getting late now in France !)
DcoderDcoder

Hi,

 

How to show the Events too, as we have shown tasks. The problem is, to a pageblocktable we can pass a list of an Object. But how to pass the list of Tasks & Events (in a single variable)? I am trying to show Tasks and Events both in a single pageblocktable. Kindly guide me.

 

Thanks!