Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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 confused..how 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.opportunityid=o.id;
>                  
>                  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 record.so how do i save the value of the id in child opportunity line item record.

Thanks

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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
share|improve this answer
    
thanks mate..perfect solution...tysm..:) –  Mik Nov 17 '12 at 6:44
    
Sweet! Cheers mate! –  techtrekker Nov 17 '12 at 7:05
    
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 have updated the code..can you check.. –  Mik Nov 17 '12 at 7:35
    
Have you created a new field on the OpportunityLineItem called the ParentOpportunityLineItemId__c ? You will need to set this field with the value of the Parent Opportunity's Line Item ids. –  techtrekker Nov 17 '12 at 7:47
    
Yes I have created the field... But how to set the value of parent line item is. –  Mik Nov 17 '12 at 8:27
show 4 more comments

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 .

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.