我在更新时写了一个触发器,但是我收到了这个错误
保存错误:字段表达式的初始术语必须是具体的SObject:LIST。
我不确定是什么原因造成的。这是我的代码
trigger Update_Discount_on_QuoteLineItem on Quote (after update) {
List <QuoteLineItem> QLI = new List <QuoteLineItem>();
Map<id,double> MapSoftwareDiscount= new Map <id,double>();
Map<id,double> MapHardwareDiscount= new Map <id,double>();
Set <id> Qid= new Set<id>();
for (Quote Q: Trigger.new)
{
if (Q.Software_Discount__c!=System.Trigger.oldMap.get(Q.Id).Software_Discount__c ||Q.hardware_Discount__c!=System.Trigger.oldMap.get(Q.Id).hardware_Discount__c )
{
Qid.add(Q.id);
MapSoftwareDiscount.put(Q.id,Q.Software_Discount__c);
MapHardwareDiscount.put(Q.id,Q.hardware_Discount__c);
}
}
QLI=[select id,QuoteId,product_category__c,Discount from QuoteLineItem where QuoteId in :Qid];
for(integer i=0; i <QLI.size();i++)
{
if (QLI[i].product_category__c=='Software')
{
QLI[i].Discount=MapSoftwareDiscount.get(QLI.QuoteId); //**ERRORS OUT HERE**
}
else if(QLI[i].product_category__c=='Hardware')
{
QLI[i].Discount=MapHardwareDiscount.get(QLI.QuoteId);
}
}
update QLI;
}
答案 0 :(得分:1)
我弄清楚问题是什么。我应该一直在使用
QLI[i].Discount=MapSoftwareDiscount.get(QLI[i].QuoteId);
我没有在[i]
中添加get(QLI[i].QuoteId)
。