Search code examples
salesforceapex

Already output issue using Map in Apex


I am trying to debug Map and I want to see all data in the Map. When I print the Map using System.debug() only first item is shown in the logs and after the first item there is message that is saying already output.

Are there any workaround for seeing data in Map using System.debug() functionality?


Solution

  • You can do it by iterating all values in map

    Map<String, String> mapToPrint = new Map<String, String>();
    
    mapToPrint.put('key1', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key2', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key3', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key4', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key5', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key6', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key7', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key8', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key9', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key10', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    mapToPrint.put('key11', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry');
    Boolean contains = mapToPrint.containsKey('Blue');
    System.assertEquals(true, contains);
    
    for (String key: mapToPrint.keySet()) {
        System.debug(LoggingLevel.DEBUG, 'key: ' + key + ' --> value: ' + mapToPrint.get(key));
    }
    

    enter image description here