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
Tommy GeorgiouTommy Georgiou 

Link custom fields on Quote with Quote Line Items

Hello all,


I have custom checkbox fields in Quotes based on the the values of Product Family field. What I am looking if it's possible is when I insert Quote Line Item and it's Product Family equals with X the checkbox X will become checked. 

Any Ideas?
Best Answer chosen by Tommy Georgiou
Arunkumar RArunkumar R
Hi Tommy,

You can go with trigger, Here is the sample code,
 
trigger UpdateQuoteCheckBox on QuoteLineItem (after insert, after update)
{
    List<Quote> quoteList = new List<Quote>();
    
    for(QuoteLineItem currQli : Trigger.New)
    {
        if(currQli.Product2.Family == 'Your Product Family Name')
        {
            quoteList.add(new Quote(Id = currQli.QuoteId, Family__c = true));
        }
    }
    
    if(!quoteList.isEmpty())
    {
      update quoteList;
    }
}

 

All Answers

Arunkumar RArunkumar R
Hi Tommy,

You can go with trigger, Here is the sample code,
 
trigger UpdateQuoteCheckBox on QuoteLineItem (after insert, after update)
{
    List<Quote> quoteList = new List<Quote>();
    
    for(QuoteLineItem currQli : Trigger.New)
    {
        if(currQli.Product2.Family == 'Your Product Family Name')
        {
            quoteList.add(new Quote(Id = currQli.QuoteId, Family__c = true));
        }
    }
    
    if(!quoteList.isEmpty())
    {
      update quoteList;
    }
}

 
This was selected as the best answer
Tommy GeorgiouTommy Georgiou
Hi Arunkumar,

I tried the trigger but the custom checkbox on Quotes still remains unchecked
 
Arunkumar RArunkumar R
Tommy, i tried the above code in my dev instance it's working fine.

my suggesstion please ensure the Family name is correct while selecting products in quote line item and change the code according to your field and Product family name.

In the above code, i used standard field Family in product object. If you are using any custom field change it according to this..

This will solve your problems.
Tommy GeorgiouTommy Georgiou
You were right I needed tgo change the field for the Family. Do you happen to know anything for the test class that I will need to implement this into production?
Arunkumar RArunkumar R
Yes tommy. For deploy apex class or visualforce page, You need a test class.

You can refer this link, it will be helpful for writing test class,
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods