+ Start a Discussion
ashchanashchan 

Displaying the dynamic fields in page

 dynamically display data of various fields that were selected from the picklist.

 

 

The SOQL will retrun list<Sobject> or list<aggregateResult> ...

 

Need to display the result......

 

 

 

Regards

Ashok Chandra


Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

*********** VF page *******

<apex:page controller="displaysobjectinpicklist" >

<script>

function callactionfunction(val)

{

   

}

</script>

   <apex:form >

<Apex:outputLabel ><b>Object Name </b> : </Apex:outputLabel> <apex:SelectList value="{!val}" size="1">

 

      <apex:selectOptions value="{!Name}"></apex:selectOptions>

<apex:actionSupport event="onchange" reRender="pgblok" action="{!createquery}"/>

    </apex:SelectList>

 

    <apex:pageBlock id="pgblok" >

       

    <apex:pageBlockTable value="{!objectforquery}" var="displaydata">

        <apex:repeat value="{!fieldapiname}" var="displayfieldname">

        <apex:column value="{!displaydata[displayfieldname]}"/>

        </apex:repeat>

   

    </apex:pageBlockTable>

    </apex:pageBlock>

  </apex:form>

</apex:page>

 

*************** Apex Controller ********

public class displaysobjectinpicklist

    {

    public String val {get;set;}

     public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();

    public string forquery;

    public set<string>flds{get;set;}

    public list<string> fieldapiname{get;set;}

    public list<sobject> objectforquery{get;set;}

    public displaysobjectinpicklist ()

    {   

        val='Contact';

        objectforquery=new list<sobject>();

        flds=new set<string>();

         fieldapiname=new list<string>();

        createquery();

      

        

    }

    public List<SelectOption> getName()

    {

 

        List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();    

        List<SelectOption> options = new List<SelectOption>();

       

 

        for(Schema.SObjectType f : gd)

        {

            options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getLabel()));

            System.debug('@@@@@@@@@@@@@@@@f.getDescribe().getName()'+f.getDescribe().getName());

        }

        return options;

    }

 

    public void createquery()

    {

        system.debug('@@@@@@ val'+val);

        if(val.length()>0)

        {

            fieldapiname=new list<string>();

            forquery=null;

            Map<string,Schema.SObjectField> mpConField=schemaMap.get(val).getDescribe().fields.getMap();

            flds=mpConField.keySet();

            for(String name : flds)

            {

                Schema.DescribeFieldResult fldResult=mpConField.get(name).getDescribe();

                if(string.valueof(fldResult.getName())!='Jigsaw' || string.valueof(fldResult.getName())!='JigsawContactId' )

                fieldapiname.add(string.valueof(fldResult.getName()));

                if(forquery==null)

                {

                    forquery=string.valueof(fldResult.getName());

                   

                }

                else

                {

                    forquery=forquery+','+string.valueof(fldResult.getName());

                }

            }

        fieldapiname.sort();

        string finalquery='select '+forquery + ' from '+val+' limit 1000 ';

        system.debug('query text'+forquery+'@@Final query'+  finalquery);

        objectforquery=Database.query(finalquery);

        system.debug('!!!! after query '+objectforquery );

       

        }

    }

 

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.