0

I have created a visualforce page and custom controller. I am trying to create a list of opportunities on Account where the opportunities are related to the contacts linked to that account however the opportunities are related to a different account.

Contact A linked with Opportunity B and Account C Contact linked with Account D List of opportunities on Account C shows opportunity B

public with sharing class ApprenticeshipOpportunities_CX {
public List<Opportunity> opps {get; set;}
public List<Contact> contacts {get; set;}
public Contact con;
public Account acct;

public ApprenticeshipOpportunities_CX(ApexPages.StandardController controller){
    this.acct = (Account)controller.getRecord();
}
public List<Opportunity> getOpps(){
    contacts = [select id, account.id, opportunity__r.id from Contact where account.id =: acct.id];

    opps = [select id, Name, Account.Name, apprentice_name__c, CloseDate, Amount, Type from Opportunity where recordtype.name = 'Apprenticeships'];
    List<Opportunity> oppstodisplay = new list<Opportunity>();
    for(Opportunity o : opps){
        for(Contact c : contacts)
        if(o.apprentice_name__c == c.Opportunity__c){
            oppstodisplay.add(o);
        }

    }
    return oppstodisplay;
}
}

<apex:page standardController="Account" 
extensions="ApprenticeshipOpportunities_CX">
<style>
.fewerMore { display: none;}
</style>
<apex:form >
 <apex:pageMessages />
 <apex:detail relatedList="true"></apex:detail>
<apex:pageblock id="CustomList" title="Third Party Apprenticeship 
Opportunities"  >
   <apex:pageBlockTable value="{!opps}" var="o" rendered="
{!NOT(ISNULL(opps))}">
    <apex:column value="{!o.Name}"/>
    <apex:column value="{!o.Account.Name}"/>
    <apex:column value="{!o.Type}"/>
    <apex:column value="{!o.Amount}"></apex:column>
    <apex:column value="{!o.CloseDate}"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="
{!NOT(ISNULL(opps))}" styleClass="noRowsHeader"></apex:outputLabel>
 </apex:pageblock>
</apex:form>
</apex:page>

1 Answer 1

0

You have a conflict between the getOpps() method and the getter of your opps variable.

Just remove your opps variable declaration. You don't need it.

Then, in your getOpps() method, declare the opps variable with its type:

List<Opportunity> opps = [select id, Name, Account.Name, apprentice_name__c, CloseDate, Amount, Type from Opportunity where recordtype.name = 'Apprenticeships'];
1
  • Thanks Martin, I have removed the opps getter and the visualforce page is still returning a blank pageBlockTable.
    – Hannah
    Feb 5, 2018 at 11:25

You must log in to answer this question.

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