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
MaheemSamMaheemSam 

Update quoteline from quote

Hi, 

  Please suggest me a logic to update quotelines from quote. When quote is inserted or updated. 

Thanks
Sudhir
Best Answer chosen by MaheemSam
Prashant Pandey07Prashant Pandey07
Hi MaheemSam,

If you would like to achieve with the trigger you may use below code to update the Quoteline item.
 
trigger Populateqoutes on Quote (after update) {

set<id>ids=new set<id>();
   for(Quote a: trigger.new){
       ids.add(a.id);
   }
list<QuoteLineItem> cos=new List<QuoteLineItem>();
map<id,QuoteLineItem> mapcon=new map<id,QuoteLineItem>([select id,Quantity,QuoteId from QuoteLineItem where QuoteId =:ids]);
map<string,Quote> mapacc=new map<string,Quote>([select id,Discount,fax from Quote where id=:ids]);



   for(QuoteLineItem c: mapcon.values()){
       if(mapacc.get(c.QuoteId).Discount!=null){
           c.Quantity=mapacc.get(c.QuoteId).Discount; //you can add filed as per your requirement
           cos.add(c);
        }
   }
    update cos;
}


--
Thanks,
Prashant

All Answers

Saravana Muthu 8Saravana Muthu 8
Hi,

You can achieve it using process builder.Create process builder in 'Quote'  object.

Check the creteria as per your requirement.

Then in the update records choose Quote.QuoteLineitems as like in the below image.

User-added image

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

Thanks,
Sarav
Sweet Potato Tec
MaheemSamMaheemSam
Hi Saravana, 

     Tried your suggestion using process builder. Created a process builder on quote when it is edited/created it must update the quotelines 
     I am trying to update a disti discount and reseller discount it is not getting updated. 
     I even tried with trigger and helperclass caling them with AFTER update action its not working

     Please let me know if you have any other suggestion 


Thanks
Sudhir
 



 
Saravana Muthu 8Saravana Muthu 8
Hi,

Can you please share your process builder.?

Also can you please let me know how you are set the values for disti discount and reseller discount?

Thanks,
Sarav
Sweet Potato Tec
MaheemSamMaheemSam
Hi Sarvan, 

  Please see image below. for testing i am adding 1 and 2 as a value for discount 

    User-added image
Saravana Muthu 8Saravana Muthu 8
Hi,

Quoteline item is the child of quote. So once a quote has been added then only quote line item will be added.

So you need to create quote line item and then if you edit and save the quote record all the child record values gets updated.

To work when a quote has been created you can use create record and create quote line item using process builder with predefined values.

Thanks,
Sarav
Sweet Potato Tec

 
Prashant Pandey07Prashant Pandey07
Hi MaheemSam,

If you would like to achieve with the trigger you may use below code to update the Quoteline item.
 
trigger Populateqoutes on Quote (after update) {

set<id>ids=new set<id>();
   for(Quote a: trigger.new){
       ids.add(a.id);
   }
list<QuoteLineItem> cos=new List<QuoteLineItem>();
map<id,QuoteLineItem> mapcon=new map<id,QuoteLineItem>([select id,Quantity,QuoteId from QuoteLineItem where QuoteId =:ids]);
map<string,Quote> mapacc=new map<string,Quote>([select id,Discount,fax from Quote where id=:ids]);



   for(QuoteLineItem c: mapcon.values()){
       if(mapacc.get(c.QuoteId).Discount!=null){
           c.Quantity=mapacc.get(c.QuoteId).Discount; //you can add filed as per your requirement
           cos.add(c);
        }
   }
    update cos;
}


--
Thanks,
Prashant
This was selected as the best answer
MaheemSamMaheemSam
Hi Prashant, 

     Your code worked cool

Thanks
Sudhir
Prashant Pandey07Prashant Pandey07
Good to here. Please mark the best answer and close the thread.

--
Thanks,
Prashant