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
Vipin  PulinholyVipin Pulinholy 

How do I access subquery values from pageBlockTable

Hi,

 

I have this query in my apex class:

actvty= [ SELECT (SELECT ActivityDate, Description,Subject,who.name from ActivityHistories order by ActivityDate desc ) FROM Contact WHERE Id in :contid]; return actvty;

I am not sure how do I display this result in Visual force page. I tried the follwing but give me error.(Error: Invalid field Subject for SObject Contact)

<apex:pageBlockTable value="{!actvty}" var="t" rendered="{!NOT(ISNULL(actvty))}" > <apex:column value="{!t.Subject}"/> <apex:column value="{!t.Who.Name}"/> <apex:column value="{!t.ActivityDate}"/> </apex:pageBlockTable> <apex:outputLabel value="No records to display" rendered="{!(ISNULL(actvty))}" styleClass="noRowsHeader"></apex:outputLabel> </apex:pageblock>

 

Could you please help me ?

 

Message Edited by das on 08-03-2009 04:11 PM
Message Edited by das on 08-05-2009 03:47 PM
thangasan@yahoothangasan@yahoo

Hai

 

  Use Apex Outputfield tag

 

  <apex:outputField id="Name" value="{!actvty.ActivityDate}"/>

 

Regards

Thanga

Vipin  PulinholyVipin Pulinholy

No Luck :-(

 

I get this Error : "Error: Unknown property 'VisualforceArrayList.ActivityDate'"

Edwin VijayEdwin Vijay

I am not sure how you can access a subquery value....

 

But you can remove the subquery and make it a simple query like...

 

 

 

actvty= [ SELECT ActivityDate, Description,Subject,who.name from ActivityHistories order by ActivityDate desc WHERE Who.Id=:contid]; return actvty;

 Now you need not change your VF code.. it would work...

 

But make sure the query is correct.. i just made a guess.. You need all activity history of the particular contact right.. you can fetch it in a single query ...

 

 

Cheers!!!

 

 

Vipin  PulinholyVipin Pulinholy

I had tried this simple query before. When I tried to run this query from Apex Explorer I got this Error:

 

Query failed: INVALID_TYPE:

Error at Row:1Column:47

sObject type ‘ActivityHistories’ is not supported. If you are attemption to use a custom object,be sure to append the ‘__c’ after the entity name….

 

 

And on Apex class, I get the following Error:"Error: Compile Error: unexpected token: 'List' at line 6 column 12" . (Line 6 is : privite List<ActivityHistories> tst; )

 

Any thoughts?

 

DevAngelDevAngel

I think you want to bind to activity.ActivityHistories:

 

 

<apex:pageBlockTable value="{!actvty.ActivityHistories}" var="t" rendered="{!NOT(ISNULL(actvty))}" >

 

 

Vipin  PulinholyVipin Pulinholy

I tired this:

 

<apex:pageBlockTable value="{!actvty.ActivityHistories}" var="t" rendered="{!NOT(ISNULL(actvty))}" > <apex:column value="{!t.Subject}"/> <apex:column value="{!t.Who.Name}"/> <apex:column value="{!t.ActivityDate}"/> </apex:pageBlockTable>

Visualforce page throws this erro: "Error: Unknown property 'VisualforceArrayList.ActivityHistories'"

DevAngelDevAngel

Right, my bad.  What you have is an array list with one element since the query filters on Id.

 

In this case, you would have two collections to iterate over.  The first is the single element collection of contacts.  The second is the collection of activity histories.  This means you would use a nested repeat or a repeat with a nested pageBlock table.

 

 

<apex:repeat value="{!activies}" var="a">
<apex:repeat value="{!a.ActivityHistories}" val="ah">
...
</apex:repeat>
</apex:repeat>

 

 

 

Vipin  PulinholyVipin Pulinholy

Hi Dev,

 

I tried with nested pageblock. Now I am not getting any error. But none of the values are not showing on page.Empty Result. (But Select query returns values).

 

<apex:pageBlockTable value="{!actvty}" var="a" > <apex:repeat value="{!a.ActivityHistories}" var="m"> <apex:pageBlockTable value="{!m}" var="t" > <apex:column value="{!t.Subject}"/> <apex:column value="{!t.Who.Name}"/> <apex:column value="{!t.ActivityDate}"/> </apex:pageBlockTable> </apex:repeat> </apex:pageBlockTable>

 

Do you see anything worng with this nested block?

Message Edited by das on 08-04-2009 12:36 PM
DevAngelDevAngel

The pageBlock value needs to be m.ActivityHistories.

 

 

Cheers,

Vipin  PulinholyVipin Pulinholy

I tried this:

<apex:pageBlockTable value="{!actvty}" var="a" > <apex:repeat value="{!a}" var="m"> <apex:pageBlockTable value="{!m.ActivityHistories}" var="t" > <apex:column value="{!t.Subject}"/> <apex:column value="{!t.Who.Name}"/> <apex:column value="{!t.ActivityDate}"/> </apex:pageBlockTable> </apex:repeat> </apex:pageBlockTable>

And also tried this:

 

<apex:pageBlockTable value="{!actvty}" var="a" > <apex:pageBlockTable value="{!a.ActivityHistories}" var="t" > <apex:column value="{!t.Subject}"/> <apex:column value="{!t.Who.Name}"/> <apex:column value="{!t.ActivityDate}"/> </apex:pageBlockTable> </apex:pageBlockTable>

No luck. None of the values are printing..

 

 

Vipin  PulinholyVipin Pulinholy

I am able to get the values through apex:repeat

<apex:repeat value="{!actvty}" var="m"> <apex:repeat value="{!m.ActivityHistories}" var="n"> {!n.Subject} </apex:repeat> </apex:repeat>

I an not able to find an equvalent pageBlockTable section for the above:

 

I tried this:

 

<apex:pageblock id="CustomListEvents" title="Member Activity History" > <apex:pageBlockTable value="{!actvty}" var="a" > <apex:pageBlockTable value="{!a.ActivityHistories}" var="t" > <apex:column value="{!t.Subject}"/> <apex:column value="{!t.Who.Name}"/> <apex:column value="{!t.ActivityDate}"/> </apex:pageBlockTable> </apex:pageBlockTable> </apex:pageblock>

But not working. Any Help?

Message Edited by das on 08-05-2009 03:46 PM
ToddKruseToddKruse

Were you able to figure this out?  I am running into the same issue.

 

Thanks

 

Todd Kruse

 

todd.kruse@amentra.com 

MayeUPAEPMayeUPAEP

Hi Das!!

Did you solve this??? I've got the same problem!!!

Hope you could answer me

guest1231231guest1231231

Was this problem ever resolved?