How to get a filtered related list in Salesforce? I know that we can get a custom Related List using PageBlock Table in a VF page but i don't know how to get hyperlinks around records in related lists and actions like Edit/Delete like a standard one. Below i have posted screenshots of both related lists..1st is Native Saleforce Related List and 2nd is custom one. How to make custom related list look like the Standard one? Help!!!!

Standard Salesforce Related List which has links to records and actions as well(edit/del)

Custom (filtered) related list using a table in VF page but without links to the records(apart from Account) and no actions.


1 Answer 1


There are many variations to the solution but here is one I've used (you could use CSS better than the nbsp; and the hardcoded styles - I just grabbed this from some existing VF page in my org)

<apex:outputPanel id="oppoRelatedList">
<apex:pageBlockTable value="{!givingOpportunities}" var="o">
 <apex:column >
    <apex:facet name="header"><apex:outputText value="Action"/></apex:facet>
    <apex:outputLink title="" value="/{!o.id}/e?retURL=/{!o.id}" 
        style="font-weight: normal; color: rgb(35,111,189); text-decoration: none">Edit
    <a href="javascript:if (window.confirm('Are you sure?')) deleteOppo('{!o.Id}');" 
         style="font-weight: normal; color: rgb(35,111,189); text-decoration: none">Del</a>

 <apex:column headerValue="Name">
    <apex:outputLink value="{!URLFOR($Action.Opportunity.View,o.id)}">{!o.name}</apex:outputLink> 
 <apex:column value="{!o.otherField1}"/>
 <apex:column value="{!o.otherField2}"/>

 <!--  actionFunctions must be within apex:form tabs -->
 apex:actionFunction action="{!deleteOppo}" name="deleteOppo" reRender="oppoRelatedList, pageMsgs" >        
  <apex:param name="oppoid" value="" assignTo="{!selectedOppoId}"/>

You'll need a controller that

a) returns the list of related Opportunities in a getter for givingOpportunities

b) has a setter for the selectedOppoId to be deleted

c) has an Action Method deleteOppo that deletes the Opportunity that is something like this

    public  ID      selectedOppoId                  {get; set;}

    // ----------------------------------------------------------------------------------------
    // ACTION METHOD    - deleteOppo
    // ----------------------------------------------------------------------------------------
    public PageReference deleteOppo() {
        PageReference resPg;
        if (this.selectedOppoId != null) 
            try {delete new Opportunity(id = this.selectedOppoId);}
            catch (Exception e) {ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,' Delete of Opportunity failed, reason: ',e));
        return resPg;
  • Thanks@crop1645. This is awesome..Really helpful. I have written a controller for returning list of related opportunities. But i have no idea how to write the method for deleting(deleteOpp) the records. I am quite new to apex and VF. Can you please share the related sample code?? Thanks, Ankit Dec 4, 2014 at 13:11
  • Ankit - I added the method to the answer
    – cropredy
    Dec 4, 2014 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .