2 件の回答
Hi Rakesh,your map consist id and list, so to fill the map you have to iterate over the Product_Stock__c list:
In your Map key will be the id of Product_Stock__c and value would be List of Product_Stock__c that contains all the fields that you have in productStockList.For more reference, you can go: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htmIf you find this helpful, kindly mark this as the best answer to help others.List<Product_Stock__c> productStockList = new List<Product_Stock__c>();
Map<Id,List<Product_Stock__c>> updateProductStock = new Map<Id,List<Product_Stock__c>>();
for(Product_Stock__c stockObj : productStockList){
if(!updateProductStock.ContainsKey(stockObj.id)){
updateProductStock.put(stockObj.id, new List<Product_Stock__c>());
}
updateProductStock.get(stockObj.id).add(stockObj);
}