3

Firstly sorry I am a total apex and VF noob. I created a controller that makes a SOQL query and I would like it displayed on a VF page. Controller saves fine but the VF page complains that I'm using the incorrectly.

Visualforce Page

<apex:page Controller="initialMeeting">
  <apex:pageBlock title="Initial Meetings">
    <apex:pageBlockTable value="{!finalList}" var="Meetings">
        <apex:column >
            <apex:facet name="header">Account Name</apex:facet>
            <apex:outputField value="{!finalList.AccountId}"/>
        </apex:column>
        <apex:column >
            <apex:facet name="header">Subject</apex:facet>
            <apex:outputField value="{!finalList.Subject}"/>
        </apex:column>
        <apex:column >
            <apex:facet name="header">Date</apex:facet>
            <apex:outputField value="{!finalList.ActivityDate}"/>
        </apex:column>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

Controller

public with sharing class initialMeeting {
    public List<Event> finalList {get;set;}
    public initialMeeting() {
        List<Account> retrievedAccounts = [SELECT ID 
                                    FROM Account 
                                    WHERE Status__c = 'Active Prospect'];

        Set<String> evt = new Set<String>();
        for (Account accts : retrievedAccounts) {
            evt.add(accts.ID);
        }

        List<Event> finalList = [SELECT Id, AccountId, Subject, ActivityDate 
                            FROM Event 
                            WHERE type='Meeting' 
                            AND AccountId IN :retrievedAccounts];
    }
    public List<Event> getUsersEvents() {
        return finalList;
    }

}

Thank you so much in advance for all your help!!!!

2

You need to use Meeting as the merge field as it is an iterator individual variable

<apex:pageBlockTable value="{!finalList}" var="Meeting">
    <apex:column >
        <apex:facet name="header">Account Name</apex:facet>
        <apex:outputField value="{!Meeting.AccountId}"/>
    </apex:column>
    <apex:column >
        <apex:facet name="header">Subject</apex:facet>
        <apex:outputField value="{!Meeting.Subject}"/>
    </apex:column>
    <apex:column >
        <apex:facet name="header">Date</apex:facet>
        <apex:outputField value="{!Meeting.ActivityDate}"/>
    </apex:column>
</apex:pageBlockTable>

Also since you already defined list ,you need not create a local variable with same name as public getter

public with sharing class initialMeeting {
public List<Event> finalList {get;set;}
public initialMeeting() {
    List<Account> retrievedAccounts = [SELECT ID 
                                FROM Account 
                                WHERE Status__c = 'Active Prospect'];

    Set<String> evt = new Set<String>();
    for (Account accts : retrievedAccounts) {
        evt.add(accts.ID);
    }
    finalList = new List<Event> ();
    finalList = [SELECT Id, AccountId, Subject, ActivityDate 
                        FROM Event 
                        WHERE type='Meeting' 
                        AND AccountId IN :retrievedAccounts];
}
public List<Event> getUsersEvents() {
    return finalList;
}

}

You can also use your getter in the page getUserEvents() as {!UserEvents} in your pageblock value .

1

Your class could be way simpler:

public with sharing class initialMeeting {
public List<Event> finalList {
    get {return [SELECT Id, AccountId, Subject, ActivityDate 
                        FROM Event 
                        WHERE type='Meeting' 
                        AND AccountId IN 
                            (select id FROM Account 
                                WHERE Status__c = 'Active Prospect')];
        }
    private set;
}

or even simpler

public with sharing class initialMeeting {
  public List<Event> getFinalList()  {
    return [SELECT Id, AccountId, Subject, ActivityDate 
                        FROM Event 
                        WHERE type='Meeting' 
                        AND AccountId IN 
                            (select id FROM Account 
                                WHERE Status__c = 'Active Prospect')];
  }
}

and then use the VF page as Mohith laid out

<apex:pageBlockTable value="{!finalList}" var="Meeting">
    <apex:column >
        <apex:facet name="header">Account Name</apex:facet>
        <apex:outputField value="{!Meeting.AccountId}"/>
    </apex:column>
    <apex:column >
        <apex:facet name="header">Subject</apex:facet>
        <apex:outputField value="{!Meeting.Subject}"/>
    </apex:column>
    <apex:column >
        <apex:facet name="header">Date</apex:facet>
        <apex:outputField value="{!Meeting.ActivityDate}"/>
    </apex:column>
</apex:pageBlockTable>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.