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
RatherGeekyRatherGeeky 

Creating Custom Related List on Contracts Using Controller Extension

I'm trying to build my first actual visualforce page on my own (well, borrowing heavily from examples). And this is what I get for being too uppity. I'm stuck.

My Goal:
Create a custom list on Contracts that shows all related Opportunities (where Contract__c on the Opportunity = the currently viewed Contract Id) on the Contract page layout. Eventually, I want to create a total of the Amounts and use this to compare to the total contract value. (We have a data model where many opps can be related to one contract.)

What I Was Thinking:

I created a Contract controller extension, borrowing from this other post and following the directions here.

public class ContractExtension { public List<Opportunity> ChildOpportunities = new Opportunity[]{}; public List<Opportunity> getContractOpps() { ChildOpportunities = [SELECT o.Contract__r.Id, Amount, Id, StageName, CloseDate FROM Opportunity o WHERE o.Contract__r.Id = :System.currentPageReference().getParameters().get('id') ]; return ChildOpportunities; } }

But, when I include the reference to the extension on my visualforce page, I get an error. "Unknown constructor 'ContractExtension.ContractExtension(Apex.Pages.StandardController controlller)'

Here's my page:

<apex:page standardController="Contract" extensions="ContractExtension"> <apex:detail id="ChildOpps_v1" relatedList="true"> <apex:relatedList id="ChildOpportunities" list="Opportunities" title="Child Opportunities" subject="{!ContractOpps}"> </apex:relatedList> </apex:detail> </apex:page>

 Any helpful tips for a vf newbie?


 

 

Best Answer chosen by Admin (Salesforce Developers) 
md1md1

You need define a

 

private final Contract contr;

 

variable and then assign it as following in the constructor:

 

this.contr= (Contract)stdController.getRecord();

All Answers

SFDCDev7SFDCDev7

Hi

 

You have missed out the constructor in your extension code. Include the below code inside your class.

 

public ContractExtension(ApexPages.StandardController controller) {

}

 Hope it works.

 

-AJ

RatherGeekyRatherGeeky
AJ: Thanks for your response. 

I did try that before and tried it again, but then I get an "Unknown constructor 'ContractExtension.ContractExtension(ApexPages.StandardController controller)' error.
md1md1

You need define a

 

private final Contract contr;

 

variable and then assign it as following in the constructor:

 

this.contr= (Contract)stdController.getRecord();

This was selected as the best answer
RatherGeekyRatherGeeky
Thank you. That helped.