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
SF OperatorSF Operator 

Show multiple objects on visualforce

I want to know how can I show more than 1 object without getting an error.

This is my actual code:

Class:

this.AccountList = [Select  Owner.name
                                From Account
            this.target = this.AccountList.get(0);

Page:

<apex:pageBlockSection title="" collapsible="false" columns="2" rendered="{!target.Name != ''}">

<apex:outputText value="{!target.Name}"/> 

</apex:pageBlockSection>

Best Answer chosen by SF Operator
Agustin BAgustin B
Hi I think you have two questions open with this issue, please try this (it may contain errors but thats the idea):
Page:
<apex:pageBlockSection title="" collapsible="false" columns="2">
<apex:pageBlockTable value="{!target}" var="a">
<apex:column value="{!a.Name}"/>
</apex:pageBlockTable></apex:pageBlockSection>

Class:
this.target = [Select  Owner.name
                                From Account Where Name != ''];//With target being a List<Account>

If it helps please mark as correct so it can help others.

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

If you want to combine two different objects in a single table and display in a visual force page then use Wrapper class to combine two objects and display in your visual force page. Check this sample post to get start 
1. https://www.interactiveties.com/blog/2012/visualforce-wrapper-class.php
2. http://bobbuzzard.blogspot.co.uk/2010/09/rotating-visualforce-table.html
3. https://developer.salesforce.com/page/Wrapper_Class

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
SF OperatorSF Operator
Thanks for your fast reply, I think I explained it bad, I want to show more than 1 item from my list.
ShirishaShirisha (Salesforce Developers) 
Hi,

Sorry,it is still not clear.

You mean,you would like to display one item each from the 2 or more Objects.

If those objects are related to each other or have the common relationship with one Object then please refer this (https://developer.salesforce.com/forums/?id=906F000000093S3IAI).

If they are not related to each other then you can refer this (https://developer.salesforce.com/forums/?id=9060G000000Xdo1QAC) for sample code.

Thank you!



 
Agustin BAgustin B
Hi I think you have two questions open with this issue, please try this (it may contain errors but thats the idea):
Page:
<apex:pageBlockSection title="" collapsible="false" columns="2">
<apex:pageBlockTable value="{!target}" var="a">
<apex:column value="{!a.Name}"/>
</apex:pageBlockTable></apex:pageBlockSection>

Class:
this.target = [Select  Owner.name
                                From Account Where Name != ''];//With target being a List<Account>

If it helps please mark as correct so it can help others.
This was selected as the best answer