将一个映射值存储到另一个
Storing one Map values to Another
我只需要将值从一张地图 'which is having record from parent child nested query' 存储到另一张地图。
Please see the below code that i am trying:
Map<id,BR_OrderItem__c> FinalorderitemMap = new Map<id,BR_OrderItem__c>();
Map<id,order> ordermap = new Map<id,order>([select Id,Name,Account.Name
(select Id, name from Itens_do_pedido__r ),BR_TotalConvertedQuantity__c from Order where id in :TargetIDList ]);
for(order ordd : ordermap.values()){
FinalorderitemMap.put(ordd.id,ordd.Itens_do_pedido__r);
}
Error that i am getting here:
|System.QueryException: List has more than 1 row for assignment to SObject
Please suggest Exactly what i am doing wrong here.
All i want is to store realted child(order-item) record with corresponding order as key.
Please suggest, Thanks in Advance.
这是因为 ordd.Itens_do_pedido__r
是 List<BR_OrderItem__c>
。有两种方法可以解决这个问题。
1.Define 地图为 List<BR_OrderItem__c>
:
Map<Id, List<BR_OrderItem__c>> FinalorderitemMap = new Map<Id, List<BR_OrderItem__c>>();
2.If 你知道每个父项只有 1 个子项,那么你可以选择以下选项:
for (order ordd : ordermap.values()) {
if (ordd.Itens_do_pedido__r.isEmpty()) {
continue;
}
FinalorderitemMap.put(ordd.id, ordd.Itens_do_pedido__r[0]);
}
我只需要将值从一张地图 'which is having record from parent child nested query' 存储到另一张地图。
Please see the below code that i am trying:
Map<id,BR_OrderItem__c> FinalorderitemMap = new Map<id,BR_OrderItem__c>();
Map<id,order> ordermap = new Map<id,order>([select Id,Name,Account.Name
(select Id, name from Itens_do_pedido__r ),BR_TotalConvertedQuantity__c from Order where id in :TargetIDList ]);
for(order ordd : ordermap.values()){
FinalorderitemMap.put(ordd.id,ordd.Itens_do_pedido__r);
}
Error that i am getting here:
|System.QueryException: List has more than 1 row for assignment to SObject
Please suggest Exactly what i am doing wrong here.
All i want is to store realted child(order-item) record with corresponding order as key.
Please suggest, Thanks in Advance.
这是因为 ordd.Itens_do_pedido__r
是 List<BR_OrderItem__c>
。有两种方法可以解决这个问题。
1.Define 地图为 List<BR_OrderItem__c>
:
Map<Id, List<BR_OrderItem__c>> FinalorderitemMap = new Map<Id, List<BR_OrderItem__c>>();
2.If 你知道每个父项只有 1 个子项,那么你可以选择以下选项:
for (order ordd : ordermap.values()) {
if (ordd.Itens_do_pedido__r.isEmpty()) {
continue;
}
FinalorderitemMap.put(ordd.id, ordd.Itens_do_pedido__r[0]);
}