Hi Pranav,
To render the <apex:column> dynamically based on the number of fields queried, you should have a tap on number of fields queried in a list of string. Then use that list of fields to get the values from your list using <apex:repeat>.
For example:
String query;
public exportContactRecords()
{
String objectName = ‘Contact’;
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> fieldMap = schemaMap.get(objectName ).getDescribe().fields.getMap();
set<string> mapset = fieldMap.keyset();
Then do something like,
List<String> lstFields = new List<String>();
for ( String str:mapset )
{
lstFields.add(str);
}
Then use this lstFields List in your repeat tag, like this,
<apex:repeat value=”{!lstFields}” var=”FieldLable”>
<apex:column value=”{!c[FieldLable]}”/>
Hope this helps.
-
This reply was modified 9 years, 3 months ago by
Kumar.