0

Please help me with the below code :

Map<ID,List<DEL_Cost__c>> parntIdVscostsmap = SomeBatchMethods.fetchFinalCosts(obj.Id,boardStartDate,boardEndDate);        
Database.saveresult[] insrtedrecs = Database.insert(parntIdVscostsmap.values(),false);            

Error: Compile Error: Method does not exist or incorrect signature: void insert(Map<Id,List<DEL_Cost__c>>, Boolean) from the type Database at line 56 column 54

1 Answer 1

3

You are trying to insert a list of lists because each Map entry is itself a list, and Map.values returns a list of its values (so a list of lists). You need to flatten this into a single list first (the assumption here is that each SObject in each list of each Map entry is unique and do not represent the same actual record to insert).

Try something like:

Map<ID,List<DEL_Cost__c>> parntIdVscostsmap = SomeBatchMethods.fetchFinalCosts(obj.Id, boardStartDate, boardEndDate);
List<DEL_Cost__c> delCosts = new List<DEL_Cost__c>();

for (List<DEL_Cost__c> costs : parntIdVscostsmap.values()) {
    delCosts.addAll(costs);
}

Database.saveresult[] insrtedrecs = Database.insert(delCosts, false);            

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .