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
MRDJMRDJ 

Visual force page - dynamic columns in table

Need to add four more columns to the table which have dynamic columns in the visual force page.
The four new columns that need to be added are from different object.
In the current dynamic table there are five columns C1, C2, C3, C4 and C5 belongs to custom_obj__1. The four new columns (N1, N2, N3, N4) belonging to object custom_obj__2 should be placed next to C2, that is in between C2 and C3 and the result of the columns should be C1, C2, N1, N2, N3, N4, C3, C4, C5.
 
As I said, it's a dynamic table based on the SOQL query the columns are displayed currently and in the order C1, C2, C3, C4 and C5. The new columns data is in different object.
 
Can someone provide me guidance to achieve this requirement. Thanks.
NagendraNagendra (Salesforce Developers) 
Hi,

Though your problem is not very clear but you can use sobject to dynamically create the output field
//Controller
SObject obj = [Select Id,email,FirtName,LastName from contact limit 1];
List<String> fieldApiNames = new List<String>{'email','FirtName','LastName'}; 


//VF Page
<apex:repeat value="{!fieldApiNames}" var="field">
      <apex:outputfield value="{!obj[field]}"/>
</apex:repeat>
Mark this as solved if it's resolved.

Thanks,
Nagendra.