Activity Forums Salesforce® Discussions Can we implement foreach on map in Salesforce? Reply To: Can we implement foreach on map in Salesforce?

  • Anuj

    Member
    June 25, 2020 at 1:40 pm

    Yes, you can iterate over values method.
    Example:
    Map<ID,Target__c> mapTargets = new Map<ID,Target__c>([ Select Id, Name From Target__c Where Account__c in:TargetAccountIDs]);
    for(Target__c target : mapTargets.values()) {
    System.debug('*************** Current Target: ' + target.Name);
    }