How to display Multiple (Two) objects records in one page block table in Visual force page

Techie Revolution

To display Multiple objects records in page block table in Visualforce page

The table should display a set from the shared fields.


Headers: ID, Name, Description

Here  follow the below Visualforce page code and then apex code.

 Note:After copying the code take care of the Double Qutations

Visualforce page code:

<apex:page controller=”Test” sidebar=”false”>

<apeX:pageBlock >
<apex:pageBlockTable value=”{!vehicles}”var=”vehicle”>
<apex:column headerValue=”Id” value=”{!}” />
<apex:column headerValue=”Name” value=”{!}” />
<apex:column headerValue=”Desc” value=”{!vehicle.des}” />

Apex Code:

public with sharing class Test {

public List<Vehicle> vehicles { get; set; }
public Test() {

vehicles = new List<Vehicle>();

List<Car__C> cars = [SELECT Id, Name, Description__C FROM Car__c];
List<Plane__C> planes = [SELECT Id, Name, Description__C FROM Plane__c];

for(Car__c car : cars) {
vehicles.add(new Vehicle(car));

for(Plane__c plane : planes) {
vehicles.add(new Vehicle(plane));

public class Vehicle {
public Id id { get; set; }
public String name { get; set; }
public String…

View original post 41 more words