0

I am trying to recreate the openactivites relatedlist in VF page as i need to show all the openactivities related to a group of accounts.Here is my list on apex

relLeadsActivities =[SELECT (SELECT id,ActivityDate, Description,Subject,CreatedDate,LastModifiedDate FROM OpenActivities ORDER BY LastModifiedDate DESC ) FROM Lead WHERE id IN : leadIds];

and trying to use it in VF page

<apex:pageBlockTable var="l" value="{!relLeadsActivities}" rendered="{!relLeadsActivities.size > 0}"  id="pbtopen">
            <apex:column value="{!l.OpenActivities.subject}">

            </apex:column> 
</apex:pageBlockTable>

results in

 Invalid field subject for SObject Lead

EDIT :

Did similar to what @SFIntegator mentioned and got multiple pageblocktables for each row.

Tried out another variation

<apex:pageBlock >
        <apex:pageBlockSection columns="1" title="Openactivities"> 
            <apex:pageBlockTable var="l" value="{!relLeadsActivities}"   id="pbtopen">
                <!--<apex:column value="{!l.subject}">   -->
                <apex:repeat value="{!l.OpenActivities}" var="op">
                    <apex:column headerValue="Subject">    
                      <apex:outputLink value="/{!op.id}"  target="_blank" ><apex:outputField value="{!op.subject}" /> </apex:outputLink>
                 </apex:column>
                 <apex:column headerValue="Assigned To">    
                      <apex:outputField value="{!op.ownerID}" /> 
                 </apex:column>
                 <apex:column headerValue="Task">    
                      <apex:outputField value="{!op.isTask}" /> 
                 </apex:column>

             </apex:repeat> 
             </apex:pageBlockTable>
        </apex:pageBlockSection>    
    </apex:pageBlock>

Now this has resulted in pageblocktable without column headers

2

There is no field like "Subject" in sObject Lead. You should repeat like this.

<apex:repeat value="{!relLeadsActivities}" var="objLead">
    <apex:pageBlockTable value="{!objLead.OpenActivities}" var="a"> 
        <apex:column value={!a.subject}/>
    </apex:pageBlockTable>
</apex:repeat>

It will show multiple page block tables in page, but if you want to show in one page block table then you should create the list in controller by repeating leads because your outer query returning list of leads.

You can try something like below:-

List<Lead> leads = [SELECT (SELECT id,ActivityDate, Description,Subject,CreatedDate,LastModifiedDate FROM OpenActivities ORDER BY LastModifiedDate DESC ) FROM Lead WHERE id IN : leadIds]

List<OpenActivity> activities = new List<OpenActivity>();
for(Lead l : leads){
   for(OpenActivity oa : l.OpenActivities)
       activities.add(oa);
}

Now you can reference activities list in your pageblocktable directly without repeating outer list.

0

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.