Search code examples
salesforceapex-code

Save error: Initial term of field expression must be a concrete SObject: LIST<QuoteLineItem>


I am writing a trigger on update but i get this error

Save error: Initial term of field expression must be a concrete SObject: LIST.

I am not sure what is causing this. Here is my code

  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;



}

Solution

  • I figured out what the issue was. I should have been using

      QLI[i].Discount=MapSoftwareDiscount.get(QLI[i].QuoteId); 
    

    I didn't include the [i] in the get(QLI[i].QuoteId).