• Shravanthi
  • NEWBIE
  • 30 Points
  • Member since 2014
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,

I have a requirement where the User dynamically selects a field from the dropdown(VF select Option) and i have to check whether those field values are available in a map or not.

I have a Select Option in Vf where all the "Account" fields will be available. The selected field's API name will be set in a get set "selectedField"

public String selectedField{get;set;} // This is the String where the API name of selected field will get set

and here is my code,

List<Account> accList = new List<Account>([SELECT Id,NumberofLocations__c FROM Account WHERE NumberofLocations__c != NULL]);

Map<String,Account> accMap = new Map<String,Account>(); 

for(Account acc:accList) {
    accMap.get(acc.selectedField); // Here is the problem, I need to get the value from the map based on the field selected by the user. I get an error                                                                 selectedField does not exist in Account object.
}

I tried an alternative,

for(Account acc:accList) {
     String val = 'acc.'+selectedField;
    accMap.get(val);   // No success with this approach too. 
}


Suggestions please ??
Hi,

I have a requirement where the User dynamically selects a field from the dropdown(VF select Option) and i have to check whether those field values are available in a map or not.

I have a Select Option in Vf where all the "Account" fields will be available. The selected field's API name will be set in a get set "selectedField"

public String selectedField{get;set;} // This is the String where the API name of selected field will get set

and here is my code,

List<Account> accList = new List<Account>([SELECT Id,NumberofLocations__c FROM Account WHERE NumberofLocations__c != NULL]);

Map<String,Account> accMap = new Map<String,Account>(); 

for(Account acc:accList) {
    accMap.get(acc.selectedField); // Here is the problem, I need to get the value from the map based on the field selected by the user. I get an error                                                                 selectedField does not exist in Account object.
}

I tried an alternative,

for(Account acc:accList) {
     String val = 'acc.'+selectedField;
    accMap.get(val);   // No success with this approach too. 
}


Suggestions please ??