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
Iqra TechIqra Tech 

Dynamic query is not working of multiple Fields its only work on single field

string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+fldAPINameMap.get(selectedField)+' FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' like \'%'+criteria+'%\'';

the above Dynamic query  is working perfectly on single select feild but now i am having multiple fields to select then after run query according to selected fields so it is not working
 
Best Answer chosen by Iqra Tech
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
This should work fro you --------------------------------------
VF Page ---------
 <apex:outputPanel id="rPanel">
                <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">                
                    <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                        <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedFieldAPI1]}"/>                                                             
                    </apex:pageBlockTable>                
                    
                </apex:pageBlockSection>
            </apex:outputPanel>

=============Apex Class=======================

Add 1 public variable in class

public String selectedFieldAPI1 {get;set;}

    public void btnPerformQuery(){
        results=new List<sObject>();
        string queryFields = ''+fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+'';
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate,'+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';
        system.debug('queryStr1-='+queryStr1);
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        selectedFieldAPI1 = fldAPINameMap.get(selectedField1);
        results = database.query(queryStr1);
        System.Debug('results-='+results);
        queried = true;
        system.debug('Query performed, Queried is: '+queried);        
    }

All Answers

Raj VakatiRaj Vakati
I Guess the issue is if you Select the mutlple fields you need to pass them as comma spearated values ad whihc is not happeing now .. 

fldAPINameMap.get(selectedField) --> Only One field so you no need to use comma .. its wokring 

fldAPINameMap.get(selectedField) --> Mutliple field , you need to comman after each field select ... so its not working 

GIve me complete code so that i will look into it 
Iqra TechIqra Tech
@Raj Vakati 
thanks for the quick reply here is code
vf page :-

<apex:page controller="ObjectQueryController2" showHeader="true" tabStyle="Opportunity_Prod_Batch_Record__c" >

    <apex:form >
        <apex:pageBlock title="Query Objects">
            <apex:pageBlockSection columns="1" title="Object Selection">
                <apex:selectList title="" size="1" value="{!selectedObject}" >
                    <apex:selectOptions value="{!objectNames}"/>
                    <apex:actionSupport event="onchange" reRender="fieldSelection"/>
                    <apex:outputLabel >Select the object you would like to query</apex:outputLabel>
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Select fields to query" id="fieldSelection">
            <apex:outputPanel >
            <table>
    <thead></thead>
    <tbody>
        <tr>
            <td>
                Select Edition Name:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
        <tr>
            <td>
                Select Opportuntiy Id:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
        <tr>
            <td>
                Select Opportuntiy Name:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
         <tr>
            <td>
                Select Opportuntiy Stage:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
         <tr>
            <td>
                Select Banner Name:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
         <tr>
            <td>
                Select Stand No:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
        <!--Repeat for the others-->
    </tbody>
</table>
                </apex:outputpanel>
                </apex:pageBlockSection>
                
                <!-- Button performs a query we have the results and we have results Id. --> 
                <apex:pageBlockSection title="Search Field to Query">              
                
                <apex:inputText value="{!criteria}">
                    <apex:outputLabel value="Search Edition Name"/>
                </apex:inputText>
                <apex:commandButton action="{!btnPerformQuery}" reRender="rPanel" value="Query!"/>
            </apex:pageBlockSection>
            <apex:outputPanel id="rPanel">
                <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">
                
                        <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                         <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/> 
                                       
                    </apex:pageBlockTable>
                    
                   
                </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

controller :-

public with sharing class ObjectQueryController2 {
    public List<Contact> conts{get;set;}
    public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    private Map<String, String> fldAPINameMap = new Map<String,String>();
    //Private set on SelectOption is so that values can be set from the controller.  
    public List<SelectOption> objectNames{public get; private set;}
    public String selectedObject {get; set;}
    public String selectedField {get;set;}
    public String selectedFieldAPI {get;set;}
    private List<SelectOption> fields;
    Public string criteria{get;set;}
    public List<sObject> results{get;set;}
    public boolean queried {get;set;}
    
    // TO DO:
    // - Error handling when user selects ID or Name fields to query (Any Duplicate Fields)
    // - Handle queries of fields that are different than text
    // - Allow the selection of multiple fields
    // - Allow Mass Update of fields on queried records
    // - Insert new records
   
    public List<SelectOption> getObjFields() {        
        fields.clear();
        if(queried == null){queried = false;}
        system.debug('Page loading, Queried is: '+queried);
        
        // If an object was not selected yet, just populate the text 'Select object first'
        if(selectedObject == NULL){
            fields.add(new selectOption('Select Object First', 'Select Object First'));
        } 
                
        // if object was selected, create a list of the object's fields
        else {            
            system.debug('$$$$$' + selectedObject);
            
            //We get a string of the sOjbects using the schemaMap.
            Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getLabel();
                fields.add(new SelectOption(fieldName, fieldName));
                fldAPINameMap.put(fieldName, dfield.getname());
            }
        }
        return fields;
    }
    
    // Constructor - this method will run when the controller is instantiated
    public ObjectQueryController2(){
        objectNames = initObjNames();
        fields = new List<SelectOption>();
        List<sObject> results = new List<sObject>(); 
        String Criteria;
    }
    
    // Populate SelectOption list -
    
    // find all sObjects available in the organization
    
    private List<SelectOption> initObjNames() {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }
    
    //Instantiate the list cast records.  We pull id, Name and other needed fields for our pageBlockTable in our VF page
    
    public void btnPerformQuery(){
        
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+fldAPINameMap.get(selectedField)+' FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' like \'%'+criteria+'%\'';
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        system.Debug(queryStr1);
        results = database.query(queryStr1);
        System.Debug(results.size());
        queried = true;
        system.debug('Query performed, Queried is: '+queried);
        
    }
}

please chehk this and add your logic as u saying...........
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
For your approach, you have to use 6 different variable for getting selected value from 6 different picklist
Iqra TechIqra Tech
@Manvendra Chaturvedi 26

can you please add in my code i am unble to get it pleaase
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Add these 5 properties in controller 

public String selectedField1 {get;set;}
public String selectedField2 {get;set;}
public String selectedField3 {get;set;}
public String selectedField4 {get;set;}
public String selectedField5 {get;set;}

In Method btnPerformQuery() you have to modify your query

string queryFields = fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+','fldAPINameMap.get(selectedField2)+','fldAPINameMap.get(selectedField3)+','fldAPINameMap.get(selectedField4)+','fldAPINameMap.get(selectedField5);
string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+queryFields+' FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' like \'%'+criteria+'%\'';


Note ** -- Make sure user will select field other then ID, because LIKE operators can not be used on Id fields


==============================================================================================

 <table>
                        <thead></thead>
                        <tbody>
                            <tr>
                                <td>
                                    Select Edition Name:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Select Opportuntiy Id:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField1}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Select Opportuntiy Name:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField2}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Select Opportuntiy Stage:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField3}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Select Banner Name:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField4}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Select Stand No:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField5}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <!--Repeat for the others-->
                        </tbody>
                    </table>
Iqra TechIqra Tech
User-added image

I added your logic in my code but still facing an error while running the dynamic query

vf page:-

<apex:page controller="ObjectQueryController5" showHeader="true" tabStyle="Opportunity_Prod_Batch_Record__c" >

    <apex:form >
        <apex:pageBlock title="Query Objects">
            <apex:pageBlockSection columns="1" title="Object Selection">
                <apex:selectList title="" size="1" value="{!selectedObject}" >
                    <apex:selectOptions value="{!objectNames}"/>
                    <apex:actionSupport event="onchange" reRender="fieldSelection"/>
                    <apex:outputLabel >Select the object you would like to query</apex:outputLabel>
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Select fields to query" id="fieldSelection">
            <apex:outputPanel >
            <table>
    <thead></thead>
    <tbody>
        <tr>
            <td>
                Select Edition Name:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
        <tr>
            <td>
                Select Opportuntiy Id:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField1}">
                   <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
    
    </tbody>
</table>
                </apex:outputpanel>
                </apex:pageBlockSection>
                
                <!-- Button performs a query we have the results and we have results Id. --> 
                <apex:pageBlockSection title="Search Field to Query">              
                
                <apex:inputText value="{!criteria}">
                    <apex:outputLabel value="Search Edition Name"/>
                </apex:inputText>
                <apex:commandButton action="{!btnPerformQuery}" reRender="rPanel" value="Query!"/>
            </apex:pageBlockSection>
            <apex:outputPanel id="rPanel">
                <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">                
                        <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                         <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedField1]}"/>                                                             
                </apex:pageBlockTable>                
                   
                </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>

COntrolller :-

public with sharing class ObjectQueryController5 {
    public List<Contact> conts{get;set;}
    public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    private Map<String, String> fldAPINameMap = new Map<String,String>();
   // private Map<String, String> fldAPINameMap1 = new Map<String,String>();
 
    //Private set on SelectOption is so that values can be set from the controller.  
    public List<SelectOption> objectNames{public get; private set;}
    public String selectedObject {get; set;}
    public String selectedField {get;set;}
    public String selectedField1 {get;set;}
    public String selectedFieldAPI {get;set;}
    private List<SelectOption> fields;
    Public string criteria{get;set;}
    public List<sObject> results{get;set;}
    public boolean queried {get;set;}
    
    // TO DO:
    // - Error handling when user selects ID or Name fields to query (Any Duplicate Fields)
    // - Handle queries of fields that are different than text
    // - Allow the selection of multiple fields
    // - Allow Mass Update of fields on queried records
    // - Insert new records
   
    public List<SelectOption> getObjFields() {        
        fields.clear();
        if(queried == null){queried = false;}
        system.debug('Page loading, Queried is: '+queried);
        
        // If an object was not selected yet, just populate the text 'Select object first'
        if(selectedObject == NULL){
            fields.add(new selectOption('Select Object First', 'Select Object First'));
        } 
                
        // if object was selected, create a list of the object's fields
        else {            
            system.debug('$$$$$' + selectedObject);
            
            //We get a string of the sOjbects using the schemaMap.
            Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getLabel();
                fields.add(new SelectOption(fieldName, fieldName));
                fldAPINameMap.put(fieldName, dfield.getname());
            }
        }
        return fields;
    }
    
    // Constructor - this method will run when the controller is instantiated
    public ObjectQueryController5(){
        objectNames = initObjNames();
        fields = new List<SelectOption>();
        List<sObject> results = new List<sObject>(); 
        String Criteria;
    }
    
    // Populate SelectOption list -
    
    // find all sObjects available in the organization
    
    private List<SelectOption> initObjNames() {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }
    
    //Instantiate the list cast records.  We pull id, Name and other needed fields for our pageBlockTable in our VF page
    
    public void btnPerformQuery(){
        
        string queryFields = ''+fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+'';
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        system.Debug(queryStr1);
        results = database.query(queryStr1);
        System.Debug(results.size());
        queried = true;
        system.debug('Query performed, Queried is: '+queried);
        
    }
}

please see this where did i did wrong......please see this
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Hi Iqra Tech,

 string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';

Since you are already paasing Name and ID field in your dynamic query , you can not select Name or ID field again from PickList. If you want to give User's option to select Name field from Picklist , you have to remove Name from your dynamic query . 
 
Iqra TechIqra Tech
so you mean i need to remove id or name from Dynamic query right?
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Yes , you need to remove ID and Name field from dynamic query . 
Make sure user select fields other then ID, because LIKE operators can not be used on Id fields
Iqra TechIqra Tech
User-added image

i removed id and name and search found this errror now

User-added image

from this type i searched but found above error
Iqra TechIqra Tech
error was like Invalid Billing cityUser-added image
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
I Can see query in debug log ,and its working fine for me . 

13:39:59:060 USER_DEBUG [80]|DEBUG|queryStr1-=SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, Industry,BillingCity  FROM account WHERE Industry IN ('Oil & Gas') limit 999 


========================================Apex class ---================
public with sharing class ObjectQueryController2 {
    public List<Contact> conts{get;set;}
    public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    private Map<String, String> fldAPINameMap = new Map<String,String>();
   // private Map<String, String> fldAPINameMap1 = new Map<String,String>();
 
    //Private set on SelectOption is so that values can be set from the controller.  
    public List<SelectOption> objectNames{public get; private set;}
    public String selectedObject {get; set;}
    public String selectedField {get;set;}
    public String selectedField1 {get;set;}
    public String selectedFieldAPI {get;set;}
    private List<SelectOption> fields;
    Public string criteria{get;set;}
    public List<sObject> results{get;set;}
    public boolean queried {get;set;}
    
    // TO DO:
    // - Error handling when user selects ID or Name fields to query (Any Duplicate Fields)
    // - Handle queries of fields that are different than text
    // - Allow the selection of multiple fields
    // - Allow Mass Update of fields on queried records
    // - Insert new records
   
    public List<SelectOption> getObjFields() {        
        fields.clear();
        if(queried == null){queried = false;}
        system.debug('Page loading, Queried is: '+queried);
        
        // If an object was not selected yet, just populate the text 'Select object first'
        if(selectedObject == NULL){
            fields.add(new selectOption('Select Object First', 'Select Object First'));
        } 
                
        // if object was selected, create a list of the object's fields
        else {            
            system.debug('$$$$$' + selectedObject);
            
            //We get a string of the sOjbects using the schemaMap.
            Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getLabel();
                fields.add(new SelectOption(fieldName, fieldName));
                fldAPINameMap.put(fieldName, dfield.getname());
            }
        }
        return fields;
    }
    
    // Constructor - this method will run when the controller is instantiated
    public ObjectQueryController2(){
        objectNames = initObjNames();
        fields = new List<SelectOption>();
        List<sObject> results = new List<sObject>(); 
        String Criteria;
    }
    
    // Populate SelectOption list -
    
    // find all sObjects available in the organization
    
    private List<SelectOption> initObjNames() {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }
    
    //Instantiate the list cast records.  We pull id, Name and other needed fields for our pageBlockTable in our VF page
    
    public void btnPerformQuery(){
        
        string queryFields = ''+fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+'';
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';
        system.debug('queryStr1-='+queryStr1);
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        system.Debug(queryStr1);
        results = database.query(queryStr1);
        System.Debug(results.size());
        queried = true;
        system.debug('Query performed, Queried is: '+queried);
        
    }
}


==================VF Page --====================

<apex:page controller="ObjectQueryController2" showHeader="true">

    <apex:form >   
        <apex:pageBlock title="Query Objects">
            <apex:pageBlockSection columns="1" title="Object Selection">
                <apex:selectList title="" size="1" value="{!selectedObject}" >
                    <apex:selectOptions value="{!objectNames}"/>
                    <apex:actionSupport event="onchange" reRender="fieldSelection"/>
                    <apex:outputLabel >Select the object you would like to query</apex:outputLabel>
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Select fields to query" id="fieldSelection">
            <apex:outputPanel >
            <table>
    <thead></thead>
    <tbody>
        <tr>
            <td>
                Select Edition Name:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField}">
                    <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
        <tr>
            <td>
                Select Opportuntiy Id:
            </td>
            <td>
                <apex:selectList size="1" value="{!selectedField1}">
                   <apex:selectOptions value="{!objFields}"/>
                </apex:selectList>
            </td>
        </tr>
    
    </tbody>
</table>
                </apex:outputpanel>
                </apex:pageBlockSection>
                
                <!-- Button performs a query we have the results and we have results Id. --> 
                <apex:pageBlockSection title="Search Field to Query">              
                
                <apex:inputText value="{!criteria}">
                    <apex:outputLabel value="Search Edition Name"/>
                </apex:inputText>
                <apex:commandButton action="{!btnPerformQuery}" reRender="rPanel" value="Query!"/>
            </apex:pageBlockSection>
            <apex:outputPanel id="rPanel">
                <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">                
                        <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                         <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedField1]}"/>                                                             
                </apex:pageBlockTable>                
                   
                </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Iqra TechIqra Tech
I paseted above code and run the query but still showing error

Visualforce Error
Help for this Page
Exception: Invalid field P Stage for SObject OpportunityLineItem 


like example i am having two select field 
edition name :-  P Edition
 stage           :- P stage

according to first select field i.e Edtion name i selected P edtion field in that having Adipec 2018 values i put the value Adipec 2018 in search box and click Query button then after it is showing an above error
Iqra TechIqra Tech
I paseted above code and run the query but still showing error

Error :-
Visualforce Error
Help for this Page
Exception: Invalid field P Stage for SObject OpportunityLineItem 


like example i selected Opportuntiy line item object having custom fields and i am having two select field 
edition name :-  P Edition(1st selectd field)
 stage           :- P stage(2nd selectd field)

according to first select field i.e Edtion name i selected P edtion field in that having Adipec 2018 values i put the value Adipec 2018 in search box and click Query button then after it is showing an above error
Iqra TechIqra Tech
@Manvendra Chaturvedi 26

u der ???
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Debug your query and run it in Developer Console (query editer) . Also , check if user have visibility to this custom field .
Iqra TechIqra Tech
Yes i chehked i am login as System Admin
i
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Can you send me dynamic query from debug log .
Iqra TechIqra Tech
@Manvendra Chaturvedi 26
Happy new year 
sir i chked in debug log queery working perfectly accroding to selelected field but dont know why tthat error occurs
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Happy New Year,
Can you send , query from debug log and error which you are getting . Code you have written is correct , their must be some other issue that causing this error .
Iqra TechIqra Tech
Actually query is working fine see this debug log

|USER_DEBUG|[83]|DEBUG|queryStr1-=SELECT createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, Industry,Rating FROM account WHERE Industry IN ('oil & gas') limit 999
12:13:58.0 (281410240)|VARIABLE_ASSIGNMENT|[81]|queryFields|"Industry,Rating"
Iqra TechIqra Tech
but when we call in vf page 

  <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">                
                        <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                         <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedField1]}"/>   <--------------------- on this field we call on vf page on that time it is shwing an error like
                                                                                                                          Visualforce Error
                                                                                                                          Help for this Page
                                                                                                                         Exception: Invalid field Account Rating for SObject Account 
                                                     
                </apex:pageBlockTable>                
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Can you confirm if your List<sObect>  results conatins  Rating field . Its seems like your code
results = database.query(queryStr1);
is not returning Rating field .

This field is present in Query string but not returning from Database.query() method .
Iqra TechIqra Tech
User-added image

when i run like this 
i mean first field Banner name
           2nd field Industry
   and search according 1st field  banner name it is working

but below scrren shot i swap the fields like
 1st field Industry
 2nd field Banner name 
and searching according  1st field Industry first field like values oil & gas  then it is not working same error occurs 

see this scrren shot 

User-added image

Error while run according this

User-added image
Iqra TechIqra Tech
14:38:20.719 (3722367251)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"criteria":"Lost","fields":"0x46108a14","fldAPINameMap":"0x313de37c","objectNames":"0x29bf0d3d","queried":true,"results":"0x2864d962","schemaMap":"0x7963efb6","selectedField":"P Stage","selectedField1":"P Edition","selectedFieldAPI":"P_Stage__c","selectedFieldAPI1":"P_Edition__c","selectedObject":"opportunitylineitem"}|0x1a231f13 14:38:20.719 (3722394831)|VARIABLE_ASSIGNMENT|[EXTERNAL]|value|"List of size 999 too large to display"|0x53db2798
14:38:20.719 (3722415562)|VARIABLE_ASSIGNMENT|[18]|this.results|"List of size 999 too large to display"|0x1a231f13


did u think this will be imapcting on results ??( What ever line i bold see)
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
On VF page if you are using PageblockTable OR Apex:Repeat , their is limit to display only 1000 record . 

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_vf.htm

 
Iqra TechIqra Tech
Yes in my Dynamic query i just did that but same error occurs see

 string queryStr1 = 'SELECT createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate, '+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 9';
        system.debug('queryStr1-='+queryStr1);
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
This should work fro you --------------------------------------
VF Page ---------
 <apex:outputPanel id="rPanel">
                <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">                
                    <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                        <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedFieldAPI1]}"/>                                                             
                    </apex:pageBlockTable>                
                    
                </apex:pageBlockSection>
            </apex:outputPanel>

=============Apex Class=======================

Add 1 public variable in class

public String selectedFieldAPI1 {get;set;}

    public void btnPerformQuery(){
        results=new List<sObject>();
        string queryFields = ''+fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+'';
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate,'+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';
        system.debug('queryStr1-='+queryStr1);
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        selectedFieldAPI1 = fldAPINameMap.get(selectedField1);
        results = database.query(queryStr1);
        System.Debug('results-='+results);
        queried = true;
        system.debug('Query performed, Queried is: '+queried);        
    }
This was selected as the best answer
Iqra TechIqra Tech
yes yes we got that just need to add like this
selectedFieldAPI = fldAPINameMap.get(selectedField);
        selectedFieldAPI1 = fldAPINameMap.get(selectedField1);
        selectedFieldAPI2 = fldAPINameMap.get(selectedField2);
        selectedFieldAPI3 = fldAPINameMap.get(selectedField3);
        selectedFieldAPI4 = fldAPINameMap.get(selectedField4);
        selectedFieldAPI5 = fldAPINameMap.get(selectedField5);

and call in vf like this

 <apex:pageBlockTable value="{!results}" var="r" >                                    
                         <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedFieldAPI1]}"/> 
                        <apex:column value="{!r[selectedFieldAPI2]}"/>
                        <apex:column value="{!r[selectedFieldAPI3]}"/>
                        <apex:column value="{!r[selectedFieldAPI4]}"/>
                        <apex:column value="{!r[selectedFieldAPI5]}"/>                                                       
                </apex:pageBlockTable>                

suparb it is working thanks a lot sir see this scrren shot.....

User-added image
Iqra TechIqra Tech
Sir can get your email id so in future i will conatct you on that sir it pleasure working with you...... tahnks  a lot sir
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
No problem , 
You can mark this is best answer , if its working fine .
you can reach out to me at "manav.063057@gmail.com"


 
Iqra TechIqra Tech
thanks a lot sir sure i will contact you via mail need to learn lots of from you....
Iqra TechIqra Tech

Sir  dynamic query displaying records according to all selected field see this

User-added image


but now when i changed the object then selected field label shuld be dispaly label according to selected object can it is possible see this scrren  shot on lead 

User-added image


i need to display selected field label according to selected object under that selected field 

can it is possible ???
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
===================Vf Page =================
 <table>
                        <thead></thead>
                        <tbody>
                            <tr>
                                <td>
                                    {!objFieldLabelName}:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    {!objFieldLabelType}:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField1}">
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            
                        </tbody>
                    </table>

================Apex Class ===========================

public with sharing class ObjectQueryController2 {
    public List<Contact> conts{get;set;}
    public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    private Map<String, String> fldAPINameMap = new Map<String,String>();
    // private Map<String, String> fldAPINameMap1 = new Map<String,String>();
    
    //Private set on SelectOption is so that values can be set from the controller.  
    public List<SelectOption> objectNames{public get; private set;}
    public String selectedObject {get; set;}
    public String selectedField {get;set;}
    public String selectedField1 {get;set;}
    public String selectedFieldAPI {get;set;}
    public String selectedFieldAPI1 {get;set;}
    
    public String objFieldLabelName {get;set;}
    public String objFieldLabelType {get;set;}
    
    private List<SelectOption> fields;
    Public string criteria{get;set;}
    public List<sObject> results{get;set;}
    public boolean queried {get;set;}
    
    // TO DO:
    // - Error handling when user selects ID or Name fields to query (Any Duplicate Fields)
    // - Handle queries of fields that are different than text
    // - Allow the selection of multiple fields
    // - Allow Mass Update of fields on queried records
    // - Insert new records
    
    public List<SelectOption> getObjFields() {        
        fields.clear();
        if(queried == null){queried = false;}
        system.debug('Page loading, Queried is: '+queried);
        
        // If an object was not selected yet, just populate the text 'Select object first'
        if(selectedObject == NULL){
            fields.add(new selectOption('Select Object First', 'Select Object First'));
        } 
        
        // if object was selected, create a list of the object's fields
        else {            
            system.debug('$$$$$' + selectedObject);
            
            //We get a string of the sOjbects using the schemaMap.
            Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getName();
                if(selectedObject.endsWithIgnoreCase('Account')){
                    if(fieldName =='Industry'){
                        objFieldLabelName  = fieldName ;
                    }
                    
                    if(fieldName =='Type'){
                        objFieldLabelType = fieldName ;
                    }
                }
                if(selectedObject.endsWithIgnoreCase('Case')){
                    // add field for case object
                }
                
                system.debug('fieldName-='+fieldName );
                
                fields.add(new SelectOption(fieldName, fieldName));
                fldAPINameMap.put(fieldName, dfield.getname());
            }
        }
        return fields;
    }
    
    // Constructor - this method will run when the controller is instantiated
    public ObjectQueryController2(){
        objectNames = initObjNames();
        fields = new List<SelectOption>();
        // List<sObject> results = new List<sObject>(); 
        String Criteria;
    }
    
    // Populate SelectOption list -
    
    // find all sObjects available in the organization
    
    private List<SelectOption> initObjNames() {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }
    
    //Instantiate the list cast records.  We pull id, Name and other needed fields for our pageBlockTable in our VF page
    
    public void btnPerformQuery(){
        results=new List<sObject>();
        string queryFields = ''+fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+'';
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate,'+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';
        system.debug('queryStr1-='+queryStr1);
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        selectedFieldAPI1 = fldAPINameMap.get(selectedField1);
        results = database.query(queryStr1);
        System.Debug('results-='+results);
        queried = true;
        system.debug('Query performed, Queried is: '+queried);
        
    }
}
Iqra TechIqra Tech
User-added image

it is not working properly i am selected Lead object and in 1st picklist City but label showing Industry 
and 2nd picklist Company but label showing Type 
Iqra TechIqra Tech
i need dynamically change label on selected field when i select any object according to this i need fields label of selected field dynamically
Iqra TechIqra Tech
like i selected Lead object
then fild label (SHow) :- 1st selected field (Show)
field lable (City)          :- 2nd slected field (City)
field label (Agent)      :- 3rd selectd field (Agent)

or 2nd example  on i Sekected Account Object:-

then fild label (Industry) :- 1st selected field (Industry)
field lable (Account Rating)          :- 2nd slected field (Account Rating)
field label (Company Type)      :- 3rd selectd field (Company Type)

like this i need to show dynamically changed field label on selcted object on that sleected field



 
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
==============Vf Page ================
<apex:page controller="ObjectQueryController2" showHeader="true">
    
    <apex:form >   
        <apex:pageBlock title="Query Objects">
            <apex:pageBlockSection columns="1" title="Object Selection">
                <apex:selectList title="" size="1" value="{!selectedObject}" >
                    <apex:selectOptions value="{!objectNames}"/>
                    <apex:actionSupport event="onchange" reRender="fieldSelection"/>
                    <apex:outputLabel >Select the object you would like to query</apex:outputLabel>
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Select fields to query" id="fieldSelection">
                <apex:outputPanel >
                    <table>
                        <thead></thead>
                        <tbody>
                            <tr> 
                                <td>
                                    {!objFieldLabelName}:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField}">
                                        <apex:actionSupport event="onchange" action="{!setFieldLabel}" reRender="fieldSelection"/>                                        
                                        <apex:selectOptions value="{!objFields}" />
                                    </apex:selectList>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    {!objFieldLabelType}:
                                </td>
                                <td>
                                    <apex:selectList size="1" value="{!selectedField1}">
                                        <apex:actionSupport event="onchange" action="{!setFieldLabel}" reRender="fieldSelection"/>  
                                        <apex:selectOptions value="{!objFields}"/>
                                    </apex:selectList>
                                </td>
                            </tr>
                            
                        </tbody>
                    </table>
                </apex:outputpanel>
            </apex:pageBlockSection>
            
            <!-- Button performs a query we have the results and we have results Id. --> 
            <apex:pageBlockSection title="Search Field to Query">              
                
                <apex:inputText value="{!criteria}">
                    <apex:outputLabel value="Search Edition Name"/>
                </apex:inputText>
                <apex:commandButton action="{!btnPerformQuery}" reRender="rPanel" value="Query!"/>
            </apex:pageBlockSection>
            <apex:outputPanel id="rPanel">
                <apex:pageBlockSection title="Results" id="results" rendered="{!queried}">                
                    <apex:pageBlockTable value="{!results}" var="r" id="Opp">                                    
                        <apex:column value="{!r.id}"/>
                        <apex:column value="{!r['createdBy.name']}"/>
                        <apex:column value="{!r['createdDate']}"/>
                        <apex:column value="{!r['lastModifiedBy.name']}"/>
                        <apex:column value="{!r['lastModifiedDate']}"/>
                        <apex:column value="{!r[selectedFieldAPI]}"/>
                        <apex:column value="{!r[selectedFieldAPI1]}"/>                                                             
                    </apex:pageBlockTable>                
                    
                </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>


====================APex controller ===============
public with sharing class ObjectQueryController2 {
    public List<Contact> conts{get;set;}
    public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    private Map<String, String> fldAPINameMap = new Map<String,String>();
    // private Map<String, String> fldAPINameMap1 = new Map<String,String>();
    
    //Private set on SelectOption is so that values can be set from the controller.  
    public List<SelectOption> objectNames{public get; private set;}
    public String selectedObject {get; set;}
    public String selectedField {get;set;}
    public String selectedField1 {get;set;}
    public String selectedFieldAPI {get;set;}
    public String selectedFieldAPI1 {get;set;}
    
    public String objFieldLabelName {get;set;}
    public String objFieldLabelType {get;set;}
    
    private List<SelectOption> fields;
    Public string criteria{get;set;}
    public List<sObject> results{get;set;}
    public boolean queried {get;set;}
    
    // TO DO:
    // - Error handling when user selects ID or Name fields to query (Any Duplicate Fields)
    // - Handle queries of fields that are different than text
    // - Allow the selection of multiple fields
    // - Allow Mass Update of fields on queried records
    // - Insert new records
    
    public List<SelectOption> getObjFields() {        
        fields.clear();
        if(queried == null){queried = false;}
        system.debug('Page loading, Queried is: '+queried);
        
        // If an object was not selected yet, just populate the text 'Select object first'
        if(selectedObject == NULL){
            fields.add(new selectOption('Select Object First', 'Select Object First'));
        } 
        
        // if object was selected, create a list of the object's fields
        else {            
            system.debug('$$$$$' + selectedObject);
            
            //We get a string of the sOjbects using the schemaMap.
            Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getName();      
                fields.add(new SelectOption(fieldName, fieldName));
                fldAPINameMap.put(fieldName, dfield.getname());
            }
        }
        return fields;
    }
    
    // Constructor - this method will run when the controller is instantiated
    public ObjectQueryController2(){
        objectNames = initObjNames();
        fields = new List<SelectOption>();
        // List<sObject> results = new List<sObject>(); 
        String Criteria;
    }
    
    // Populate SelectOption list -
    
    // find all sObjects available in the organization
    
    private List<SelectOption> initObjNames() {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }
    
    //Instantiate the list cast records.  We pull id, Name and other needed fields for our pageBlockTable in our VF page
    
    public void btnPerformQuery(){
        results=new List<sObject>();
        string queryFields = ''+fldAPINameMap.get(selectedField)+','+fldAPINameMap.get(selectedField1)+'';
        string queryStr1 = 'SELECT ID, NAME, createdBy.Name, createdDate, lastModifiedBy.Name, lastModifiedDate,'+queryFields+'  FROM '+selectedObject+' WHERE '+fldAPINameMap.get(selectedField)+' IN (\'' + String.join( criteria.split( ',' ), '\',\'' ) +'\') limit 999 ';
        system.debug('queryStr1-='+queryStr1);
        selectedFieldAPI = fldAPINameMap.get(selectedField);
        selectedFieldAPI1 = fldAPINameMap.get(selectedField1);
        results = database.query(queryStr1);
        System.Debug('results-='+results);
        queried = true;
        system.debug('Query performed, Queried is: '+queried);
        
    }
    
    public void setFieldLabel(){
        system.debug('selectedObject-='+selectedObject);
        system.debug('selectedField-='+selectedField);
        Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getName();
                if(fieldName==selectedField){
                    objFieldLabelName = dfield.getLabel();
                }
                 if(fieldName==selectedField1){
                    objFieldLabelType = dfield.getLabel();
                }
            }
    }
}
Iqra TechIqra Tech
User-added image

sir it is working pefctly according to field select
but when we select fiild in that they are showing api name of the fields but i need labels of the fields 
see this scrren shot showing API names of the fields

User-added image
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
    public List<SelectOption> getObjFields() {        
        fields.clear();
        if(queried == null){queried = false;}
        system.debug('Page loading, Queried is: '+queried);
        
        // If an object was not selected yet, just populate the text 'Select object first'
        if(selectedObject == NULL){
            fields.add(new selectOption('Select Object First', 'Select Object First'));
        } 
        
        // if object was selected, create a list of the object's fields
        else {            
            system.debug('$$$$$' + selectedObject);
            
            //We get a string of the sOjbects using the schemaMap.
            Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
            
            for(Schema.SObjectField sfield : fieldMap.Values())
            {
                schema.describefieldresult dfield = sfield.getDescribe();
                String fieldName = dfield.getName();      
                fields.add(new SelectOption(fieldName, dfield.getLabel()));
                fldAPINameMap.put(fieldName, dfield.getname());
            }
        }
        return fields;
    }
Iqra TechIqra Tech
Thanks a lot sir it working perfctly many tahnks to you
Iqra TechIqra Tech

@Manvendra Chaturvedi 26 

Sir i have question can we do mapping with other object and past the data into other object whatever we records call on our vf page we need to store this records into the other object by simply cliking on button???
Varun Sharma 150Varun Sharma 150
Hello Friends
I have a reverse question where I have a map with Key as Name of properties of Object with values and I want to iterate over collection and assign value to relevant property i.e.

I have a custom object with 4 properties, First, Second, Third and Forth
Now I also have a Map<string, string> Values which has data as 
<First, 10>
<Second,20>
<Third, 30>
<Forth, 40>

Now I want a way to iterate over all the Keys in MAP and assign the value of corrosponding property of the object from value from MAP.
for(string keyValue : Map.GetKeys())
{
Object.Proeprty_Name = Map.Get(keyValue);
}

I also have another post for same.
Mark StvenMark Stven
Can you also integrate this code with asme pressure vessels (https://rexarc.com/) website?
alex mixsalex mixs