Saturday 21 July 2018

How to save map with List as child and Id as parent
In this following Example,I had taken case as a example
Map<Id, List<Case>> parentChildCase = new Map<Id, List<Case>>();
Map<ID, Case> childMap = new Map<ID, Case>([SELECT Id, ..., FROM Case]);

for(ID c : childMap .keySet())
{
    if(parentChildCase.containsKey(childMap .get(c).ID))
    {
        parentChildCase.get(cMap.get(c).ID).add(childMap .get(c));
    }
    else
    {
        List<Case> cases = new List<Case>();
        cases.add(childMap .get(c));
        parentChildCase.put(childMap .get(c).ID, cases);
    }
}