2

Trying to create a list of Open activities so that I can sort and display as an apexDataTable on a VF page.

I'm currently seeing the error:

Invalid field Subject for SObject Account

VF Page Snippet:

 <apex:dataTable value="{!actList}" var="TheOpenActivities" rowClasses="odd,even" styleClass="table5" rows="10">

        <apex:facet name="header">Action Plan</apex:facet>
        <apex:facet name="footer">
        See full list of open activities &gt;
        </apex:facet>

        <apex:column >
            <apex:facet name="header">Action Plan</apex:facet>
            <apex:outputLink value="/{!TheOpenActivities.ID}"> 
                <apex:outputText value="{!TheOpenActivities.Subject}"> 
                </apex:outputText> 
            </apex:outputLink>
        </apex:column>

        <apex:column >
            <apex:facet name="header">Due Date</apex:facet>
            <apex:outputText value="{0, date, dd/MM/yyyy}">
                <apex:param value="{!TheOpenActivities.ActivityDate}" />           
            </apex:outputText>
        </apex:column>

        <apex:column >
            <apex:facet name="header">Responsible</apex:facet>
            <apex:outputText value="{!TheOpenActivities.Owner.Name}" />
        </apex:column>


    </apex:dataTable>

SOQL query below:

public list<Account> getActList() {  
    Current_Acc_Id = ApexPages.currentPage().getParameters().get('id');

    List<Account> ActList = [
        SELECT (SELECT ID, Subject, ActivityDate, Status, Priority, OwnerId FROM   OpenActivities WHERE Status =:'Open') FROM Account
        WHERE account.id = :Current_Acc_Id
    ]; 

    return ActList; 
}

I'm hoping the problem is quite a simple fix (I'm currently teaching myself to use apex as I go). Can someone point out my error with an explanation so I understand what has gone wrong?

Ive reviewed the question here: System.sObjectException: Invalid Field – trying to use a nested SOQL query but don't understand how to apply the solution to my problem (if it is actually relevant).

1
  • It looks like youre using your list of accounts instead of the accounts list of activities in the visualforce page. Try adding another apex:repeat to loop over the child object. Jun 23, 2016 at 17:58

3 Answers 3

2

The issue seems to be stemming from the visualforce page, and not the nested query.

value="{!actList}" var="TheOpenActivities"

{!accList} fetches a listing of accounts, but then you name those accounts as if they were activities, and use them as such. Try adding another apex:repeat to the page, to iterate over the child activities. Make sure to rename the list var, to avoid future confusion.

<apex:repeat var="account" value="{!actList}">
    <apex:repeat var="activity" value="{!account.OpenActivities}">
        <apex:column>
            <apex:facet name="header">Action Plan</apex:facet>
            <apex:outputLink value="/{!activity.ID}"> 
                <apex:outputText value="{!activity.Subject}"> 
                </apex:outputText> 
            </apex:outputLink>
        </apex:column>
    </apex:repeat>
</apex:repeat>
2
  • You should probably rename the TheOpenActivities var to be less confusing. Might be most clear if you show both repeat tags.
    – Adrian Larson
    Jun 23, 2016 at 18:13
  • @AdrianLarson I totally agree, Ill make those edits. Jun 24, 2016 at 13:04
2

May be you can try below code,

<apex:repeat value="{!ActList}" var="account">
    <apex:pageBlockTable value="{!account.OpenActivities}" var="activity">
      <apex:column value="{!activity.subject}"/>
    </apex:pageBlockTable>
</apex:repeat>

You need to iterate two lists here. First for actList and other for OpenActivities.

1

Below correction will make things work:

<apex:repeat value="{!actList}" var="acc">
    <apex:dataTable value="{!acc.OpenActivities}" var="TheOpenActivities" rowClasses="odd,even" styleClass="table5" rows="10">
    .
    .
    .

</apex:repeat>

External repeat tag iterates on list of accounts and internal datatable iterates on activities associated with each account.

{!acc.OpenActivities}

will give you activities associated with every account returned by SOQL.

1
  • List<Account> has no property OpenActivities. I believe your answer is incorrect and will not even compile.
    – Adrian Larson
    Jun 23, 2016 at 18:35

You must log in to answer this question.

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