Thursday, July 19, 2012

Iterating Map using for loop in Apex Class


You can user keyset() method to iterate over keys in map to fetch values
Apex Class:
Map<String,String> fieldList = new Map<String,String>{‘Name__c’=>’Name’, ‘Age__C’=>’Age’};
for (String fieldName : fieldList.keySet()){
system.debug(fieldName);
}

2 comments:

  1. Hi, How can I display the value as well as this will display Namee__c and Age__c

    Thanks

    ReplyDelete
  2. I just figure it out
    system.debug(fieldName + ' value: ' + fieldList.get(fieldName));

    ReplyDelete