I am trying the below code to add field history and product as a related list of opportunity in vf page, but its not working .
<apex:relatedList list="OpportunityFieldHistory"/>
<apex:relatedList list="Product"/>
Can anyone tell me what is the correct way to write it.
Regards
Edit:
There are two Standard objects that have Opportunity history information, OpportunityFieldHistory and OpportunityHistory. The relatedList component works fine with a value of OpportunityHistories
for the list
attribute, but an error is thrown when using the value of Histories
, even though the SObject describe information shows "Histories" as the child relationship name.
<apex:relatedList list="OpportunityHistories"/> <!-- Works fine -->
<apex:relatedList list="Histories"/> <!-- Error -->
Best Answer
Actually there are no easy ways to show the Account, Opportunity, Case histories through the
<apex:relatedList/>
.Though from the API it is found relationship name is
'Histories'
but those are not accessible through the related List.We need to have custom coding to display the Opportunity History table.
I have taken the code as provided in this link History related list in Visualforce and it is perfectly working.
Hopefully it will help to all Salesforce developers like us.
Visualforce Component (GenericHistoryComponent)
Apex Controller (GenericHistoryComponentController)
Usage of component in Visualforce page (OpportunityRelatedList)
<c:GenericHistoryComponent recordLimitAttribute="50" myObjectAttribute="{!Opportunity}"/>
<!--it will display Stage History -->
Access visualforce page as follows:
/apex/OpportunityRelatedList?id=<OpportunityId>
Expected Results