+ Start a Discussion
nwingnwing 

How to add child custom object records of a product to a quote line item after insert

I am trying to trigger the addition of related records (call them sub/bundle items) when a product is added via the quote line item object.

 

So simply put, when someone adds a product that happens to have child items, add those child items to the related list on the quote line item object.

 

I tracked the issue back to the fact that the ProductName and the ProductId variables below are coming up empty.  The PriceBookId is a required field on the quote line item, and I am adding that in the test class, hardcoded.  So I would assume that AFTER the quote line item is inserted I could reference that price book entry and its related object info just fine, as I have in other cases.......but no such luck so far.

 

Here is the trigger code.  As I mentioned the last two variables are coming up blank.  Any help greatly appreciated.....lost enough hair over this one already.

 

trigger

AfterInsertQuoteLineItem_trg on QuoteLineItem (after insert) {

 

for (QuoteLineItem i : Trigger.new)

 

 

{

String QuoteLineItemId = i.Id;

 

String ProductName = i.PriceBookEntry.Product2.Name;

 

String ProductId = i.PriceBookEntry.Product2Id;

 

 

SurekaSureka

Hi,

 

You will not be able to use like "i.PriceBookEntry.Product2.Name;". From the PriceBookentry Query the product and then use Product2.Name.

 

Thanks