0

I am fetching all the field of an object after selecting one object from the dropdown list. With field I am showing checkbox, now I want to show all the field data that I selected using checkbox in VF page.

How to show field value of that particular selected field? Process Selected

public class ProcessSelected 
 { 


public String obj;
public List<String> objFields {get;set;}


public void processSelected() {

}

public String getobj()
{
    return obj;
}

public void setobj(String obj)
{
    this.obj = obj;
}   

public List<SelectOption> getobjs()
{
    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().getName()));
    }
    return options;
}

public void fetchFields()
{ 
    List<String> fields = new List<String>();
    Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
    Schema.sObjectType objType = globalDescription.get(obj); 
    Schema.DescribeSObjectResult r1 = objType.getDescribe(); 

    Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();  

    for(Schema.SObjectField field : mapFieldList.values())  
    {  
        Schema.DescribeFieldResult fieldResult = field.getDescribe();  

        if(fieldResult.isAccessible())  
        {  
            fields.add(fieldResult.getName());
        }  
    }
    List<String> so = new List<String>();
    for(String f : fields)
    {
        so.add(f);
    } 
    objFields = so;       
}  

}

7
  • using apex:outputfield tag to display. Or better if you can share your code and tell us where are you facing problem. Commented Sep 8, 2016 at 4:48
  • Do you want to display record as well? Commented Sep 8, 2016 at 4:56
  • Yes record of selected fields.
    – avidForce
    Commented Sep 8, 2016 at 4:57
  • Seems you need to add a query in there using the object fields to construct the query string. Then you can use that in the table
    – Eric
    Commented Sep 8, 2016 at 5:02
  • Yes and we have to query only those selected fields.
    – avidForce
    Commented Sep 8, 2016 at 5:03

1 Answer 1

1

You need to make Dynamic SOQL and a list of all selected field then on VF . Do something like

<apex:page controller="controller" >
  <apex:form >
       <apex:pageBlockTable value="{!objectforquery}" var="displaydata">//objectforquery is list of object which you fetch 
        <apex:repeat value="{!fieldapiname}" var="displayfieldname"> //fieldapiname is name of field list
        <apex:column value="{!displaydata[displayfieldname]}"/>
       </apex:repeat>

      </apex:pageBlockTable>
    </apex:pageBlock>
  </Apex:form>
</apex:page>

To make dynamic query you need to do something like

String queryFields = '';
        for(Schema.FieldSetMember f : SObjectType.Account.FieldSets.Example_Fieldset.getFields()) {
            if(queryFields.length() > 0) {
                queryFields += ', ';
            }
            queryFields += f.getFieldPath();
        }
        //Query the records you want to display
        this.accounts = Database.query(
            ' SELECT ' +
                queryFields +
            ' FROM ' +
                ' Account ' +
            ' LIMIT 10 ');
1
  • Thanx! @Tushar, will try that.
    – avidForce
    Commented Sep 8, 2016 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .