Find your content:

Search form

You are here

update record(opportunitylineitem) of child opportuity...when parent opportunity record(opportunitylineitem) is updated..?


My scenario:

When i insert opportunity line-item on Parent Opportunity...opportunity line-item are also created on child opportunity(same as line-item on Opportunity).If there are 2 child opportunities then same opportunity line-items records will be created on both the child opportunity.

My problem is i have a button on opportunity when clicked on that a VF page opens and shows opportunity line-item records(editable) of parent opportunity.if i update any line-item record of parent opportunity then the child-opportunity line-item record should also be updated on all the child opportunities

As IDS of both opportunity line items records are different on child and parent opportunity. How to update child opportunity(opportunity line-item record) id parent opportunity opportunity line-item records are updated.

I am slightly should i do this..

I am able to able update the parent opportunity (opportunity line-item records). But how to update child-opportunity opportunity line-item records. Also I am able to get the ids of child opportunity opportunity line-item records.I dont know how to use them...Please help... UPDATED CODE

>  for(opportunity o:oppchildlist)
>          {
>              for(opportunitylineitem ol : opllist)
>              {
>                  opline=new opportunitylineitem();
>        ;
>                  opline.PricebookEntry=ol.PricebookEntry;
>                  opline.PricebookEntryid=ol.PricebookEntryid;
>                  opline.Business_Type__c=ol.Business_Type__c;

>                  childoppitem.add(opline);
>              }
>          }

Hey i am thinking of implementing the fourth solution..but i have doubt how do i stamp the value of the Parent OpportunityLineItem at create.i mean as the parent opportunity line item record is not created so we dont have the id of that how do i save the value of the id in child opportunity line item record.


Attribution to: Mik

Possible Suggestion/Solution #1

If you have Parent Oppurtunity Id then obviously you will be able to get all child oppurtunities .Now query all line items from the Oppurtunity Id(Parent and Child) and you can update all line items .

Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #2

A few ways I can think of:

One - always delete the line items on child opportunity and create afresh on every change on the parent, as a copy from the parent. Too much DML.

Two - create a custom formula field on OpportunityLineItem which is a composite key, eg PriceBookEntryId+Quantity, which will evaluate to the same on parent and child OpportunityLineItems and therefore you can match using the formula field composite key.

Three - (Recommended) If you can be sure that a Product is added only once, then you can match on the PriceBookEntryId, because this will be the same on Parent and Child Opportunity Line Items. This sounds the most promising provided the precondition is met.

Four - create a hidden text field on OpprtunityLineItem, into which you stamp the value of the Parent OpportunityLineItem at create. Then for every subsequent change you can match by the parent OpportunityLineItem Ids that are changing and accordingly update all related child OpportunityLineItem Ids.

Sample Code for Solution Four :

Create a hidden field ParentLineItemId__c on OpportunityLineItem (Text, 18) Then in your inner for loop, you can set this

opline.ParentLineItemId__c=ol.Id; //set the Parent OLI Id on the Child OLI

Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content