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
MayeUPAEPMayeUPAEP 

How to display a Subquery in a visualforce

I need your help. I've a subquery and Im' trying to display it in a visualforce page without any results:

 

My Class:

 

 

	public List<SObject> getOpen()
		{
	
		SObject[] Cuenta = [SELECT Name, 
		         (Select Subject, WhoId, WhatId, Id, IsTask, ActivityDate, Status, Priority, OwnerId FROM OpenActivities  
		          WHERE OwnerID =:USER_ID ORDER BY ActivityDate ) 
		          From Account WHERE id=:RECORD_ID];
		Actividades = Cuenta.get(0).getSObjects('OpenActivities'); 
                //This is just to verify the Actividades list
		for(Integer i=0; i<Actividades.size(); i++)
			{
			System.debug('********Sobject'+Actividades[i]);
			}
		return Actividades;
		}		

 

In my page I want to display the Subject, WhoId, WhatId, etc.

 

If I put:

 

 

	<apex:pageBlock title="Actividades Abiertas" >    
		<apex:dataTable value="{!Open}" var="each" cellpadding="10" border="0" styleClass="list">
			<apex:column headerValue="Acción">{!each}</apex:column>
	</apex:pageBlock>

 

 

I have my 5 id's open activities without a problem.  But if I put:

 

 

	<apex:pageBlock title="Actividades Abiertas" >    
		<apex:dataTable value="{!Open}" var="each" cellpadding="10" border="0" styleClass="list">
			<apex:column headerValue="Acción">{!each.Subject}</apex:column>
	</apex:pageBlock>

 

 

I've got an error ' SObject.Subject Property Unknown'

 

In my debug log I have my list with all the data

 

 

11:10:0.928|USER_DEBUG|[44,4]|DEBUG|********SobjectOpenActivity:{Status=No iniciada, AccountId=001R000000QAo87IAD, WhatId=001R000000QAo87IAD, Subject=Llamada, WhoId=003R000000MurqIIAR, OwnerId=005400000010CwqAAE, IsTask=true, Id=00TR0000008DY1OMAW, ActivityDate=2010-04-09 00:00:00, Priority=Normal}

11:10:0.931|USER_DEBUG|[44,4]|DEBUG|********SobjectOpenActivity:{Status=No iniciada, AccountId=001R000000QAo87IAD, WhatId=a0BR0000002ppkaMAA, Subject=Enviar Encuesta, WhoId=003R000000MurqIIAR, OwnerId=005400000010CwqAAE, IsTask=true, Id=00TR0000008DiZNMA0, ActivityDate=2010-04-26 00:00:00, Priority=Normal}

11:10:0.933|USER_DEBUG|[44,4]|DEBUG|********SobjectOpenActivity:{Status=No iniciada, AccountId=001R000000QAo87IAD, WhatId=001R000000QAo87IAD, Subject=Generar Reporte, WhoId=003R000000MurqIIAR, OwnerId=005400000010CwqAAE, IsTask=true, Id=00TR0000008DY2nMAG, ActivityDate=2010-04-28 00:00:00, Priority=Normal}

11:10:0.936|USER_DEBUG|[44,4]|DEBUG|********SobjectOpenActivity:{AccountId=001R000000QAo87IAD, WhatId=a0BR0000002ppkaMAA, Subject=Reunión, WhoId=003R000000MurqIIAR, OwnerId=005400000010CwqAAE, IsTask=false, Id=00UR0000004Y5fYMAS, ActivityDate=2010-07-20 00:00:00}

11:10:0.939|USER_DEBUG|[44,4]|DEBUG|********SobjectOpenActivity:{AccountId=001R000000QAo87IAD, WhatId=001R000000QAo87IAD, Subject=Reunion, WhoId=003R000000MurqIIAR, OwnerId=005400000010CwqAAE, IsTask=false, Id=00UR0000004Y5cFMAS, ActivityDate=2010-10-19 00:00:00}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ThomasTTThomasTT

 

public List<SObject> getOpen()

 

 

Type "SObject" doesn't have Subject field. Change the signature to

 

 

public List<OpenActivity> getOpen()

 (of course, you need to cast what you need to return)

 

 

and VF Page will be

<apex:dataTable value="{!Open}" var="each">
    <apex:outputField value="{!each.Subject}"/>
</apex:dataTable>

 

ThomasTT

 

All Answers

blombardisblombardis

Hi Mayela,

 

I think to access the Subject you need to access {!each.OpenActivities.Subjct}

 

Please let me know if this works.

 

<apex:pageBlock title="Actividades Abiertas" >    
		<apex:dataTable value="{!Open}" var="each" cellpadding="10" border="0" styleClass="list">
			<apex:column headerValue="Acción">{!each.OpenActivities.Subject}</apex:column>
MayeUPAEPMayeUPAEP

Hi!!

It doesn't work either!!! :smileysad: 

Same error:  'SObject.OpenActivities Property Unknown'

ThomasTTThomasTT

 

public List<SObject> getOpen()

 

 

Type "SObject" doesn't have Subject field. Change the signature to

 

 

public List<OpenActivity> getOpen()

 (of course, you need to cast what you need to return)

 

 

and VF Page will be

<apex:dataTable value="{!Open}" var="each">
    <apex:outputField value="{!each.Subject}"/>
</apex:dataTable>

 

ThomasTT

 

This was selected as the best answer
MayeUPAEPMayeUPAEP

ThomasTT,

THANKS A LOT!!!! You're right with this change my VF works great!!!!!

 

For all who have the same problem here is the final code:

 

VF Page:

 

 

	<apex:pageBlock title="Actividades Abiertas" >    
		<apex:dataTable value="{!Open}" var="each" cellpadding="10" border="0" styleClass="list">
			<apex:column headerValue="Asunto">{!each.Subject}</apex:column>
			<apex:column headerValue="Nombre">{!each.WhoId}</apex:column>
			<apex:column headerValue="Relacionado con">{!each.WhatId}</apex:column>
		</apex:dataTable>  
	</apex:pageBlock>

 

 

Class:

 

 

.
.
.
	public List<OpenActivity> Actividades {get; set;}
.
.
.
	

	public List<OpenActivity> getOpen()
		{
		
		SObject[] Cuenta = [SELECT Name, 
		         (Select Subject, WhoId, WhatId, Id, IsTask, ActivityDate, Status, Priority, OwnerId FROM OpenActivities  
		          WHERE OwnerID =:USER_ID ORDER BY ActivityDate ) 
		          From Account WHERE id=:RECORD_ID];
		Actividades = (List<OpenActivity>)Cuenta.get(0).getSObjects('OpenActivities'); 
		return Actividades;
		}		
}