You need to sign in to do that
Don't have an account?
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 ?
Hai
Use Apex Outputfield tag
<apex:outputField id="Name" value="{!actvty.ActivityDate}"/>
Regards
Thanga
No Luck :-(
I get this Error : "Error: Unknown property 'VisualforceArrayList.ActivityDate'"
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!!!
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?
I think you want to bind to activity.ActivityHistories:
<apex:pageBlockTable value="{!actvty.ActivityHistories}" var="t" rendered="{!NOT(ISNULL(actvty))}" >
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'"
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>
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?
The pageBlock value needs to be m.ActivityHistories.
Cheers,
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..
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?
Were you able to figure this out? I am running into the same issue.
Thanks
Todd Kruse
todd.kruse@amentra.com
Hi Das!!
Did you solve this??? I've got the same problem!!!
Hope you could answer me
Was this problem ever resolved?
I solved it.
Check this link
http://community.salesforce.com/t5/Apex-Code-Development/How-to-display-a-Subquery-in-a-visualforce/m-p/179606#M28413
Hope It will help you