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
manishtiwary1.390210540410199E12manishtiwary1.390210540410199E12 

How to show only Open opportunity in Opportunity tab

I have used tab insted of Related list .Can we show only oppoen opportunity under Opportunity tab related with account.
PFB snap and code
Should show only open opportunity
<apex:page standardController="Account" showHeader="true"
tabStyle="account" >
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:relatedList subject="{!account}" list="contacts" />
</apex:tab>
<apex:tab label="Opportunities" name="Opportunities"
id="tabOpp">
<apex:relatedList subject="{!account}"
list="opportunities" />
</apex:tab>
<apex:tab label="Open Activities" name="OpenActivities"
id="tabOpenAct">
<apex:relatedList subject="{!account}"
list="OpenActivities" />
</apex:tab>
<apex:tab label="Notes and Attachments"
name="NotesAndAttachments" id="tabNoteAtt">
<apex:relatedList subject="{!account}"
list="CombinedAttachments" />
</apex:tab>

<apex:tab label="Account Team"
name="AccountTeams" id="AccountTeams">
<apex:relatedList subject="{!account}"
list="AccountTeams" />
</apex:tab>

</apex:tabPanel>
</apex:page>
PratikPratik (Salesforce Developers) 
Hi Manish,

I think you will have to write an extension to this standardcontroller and there write logic to override getopportunities method to get open opprtunities (IsClosed=false).


Here is the sample code i tried and it worked:

VF Page:

<apex:page standardController="account" extensions="ovrrideopp">
  
  <apex:tabPanel >
  
  <apex:tab label="contacts" >
  <apex:relatedList list="contacts"/>
  
   </apex:tab>
   
   <apex:tab label="Opprtunities" >
   <apex:pageBlock >
   <apex:pageBlockTable value="{!opplist}" var="op">
   <apex:column value="{!op.name}"/>
   <apex:column value="{!op.stagename}"/>
   
   </apex:pageBlockTable>
   
   </apex:pageBlock>
   </apex:tab>
  
  </apex:tabPanel>
  <apex:detail relatedList="false"/>
</apex:page>

Controller:

Public class ovrrideopp{
Public string accid;
public list<opportunity> opplist{get;set;}

    public ovrrideopp(ApexPages.StandardController controller) {

  accid = ApexPages.currentPage().getparameters().get('id');
  opplist= [select name,stagename from opportunity where accountid=:accid AND isClosed=False];
 
    }

}


Let me know how it goes for you!

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.