Activity Forums Salesforce® Discussions How to select all fields of an object dynamically on Salesforce visualforce page?

  • Kumar

    Member
    January 18, 2017 at 1:29 pm

    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 7 years, 10 months ago by  Kumar.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos