function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
trictric 

Opportuntiy and Quotelineitems

Hi Firends,

In the below given code I am getting an error message variable r.opporunityid not found .I understand and why this error has been coming.I am not able to rectify.Can somebody please help me.The variable r belongs to the the loop which has been highlighted below with blue color and when I try to acces it limes which are in red ,it gives an error meesage variable r does not exists as it is local to the for loop ,hence not accessible to the lines in Red.

 

 

Can somebody please help ?

 

trigger Quote1 on QuoteLineItem (after update) {

static Double d=0;
Map<id,double> i=new map<id,double>();
//list<quotelineitem>l=new list<quotelineitem>();>
list<quotelineitem>l=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newmap.keyset()];
for(quotelineitem d1:l)
{
d=d+d1.totalprice;
i.put(d1.quoteid,d);
System.debug('The value in the map variable of type mao is'+i.get(d1.quoteid));
}
Map<id,double>sat=new Map<id,double>();
list<quote> s=[select id,opportunityid,Totalprice from quote where id in:i.keyset()];


Double temp=0;
for(quote r:s)
{

temp=i.get(r.id);
temp=temp+r.totalprice;
sat.put(r.opportunityid,temp);

}

//list<opportunity>opp1=[Select Amount, (Select TotalPrice From Quotes) From Opportunity where id in:sat.keyset()];

//for(opportunity soal:opp.quotes)
//{

 

//}
list<opportunity> lap=[select id,amount from opportunity where id in:sat.keyset()];
list<opportunity> crop;
for(opportunity opp:lap)
{


opp.amount=sat.get(r.opportunityid);

//System.debug('The value in the
crop.add(opp);
}
update crop;
}

 

Thanks,

Trick.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
NiketNiket

Hi ,

 

I believe you understand that " r " is a locally declared variable so you can't use it later in the line which is marked red.

 

Please use this line in place of your red line :

 

opp.amount=sat.get(opp.id);

 

I think it should work. Please try this and let me know if it works or not .

 

Please mark it as the solution if it answers your question and if you have any question, let me know.

 

Ckeck My Blog