+ Start a Discussion
Krishna Prasad K PKrishna Prasad K P 

How to get the parent opportunity ID in the trigger while clonning..??

Hi All,
I have a before insert trigger on opportunity.
I have a new requirement :
       When user clones an opportunity I need to get some field values from the parent opp, and after some calculation on these values, the result has to be set  to a field in the opportunity being inserted. Also some fields have to be copied from the parent opp to the new child opp.
       Problem is that, almost all these fields are not in the layout. So clonning doesnt copy those fields to the child opp. So these fields have to be queried  from the parent opp using SOQL. 
 
       Inserting parent opp ID into any of the input field on edit mode is not preferred!!(like  https://na9.salesforce.com/<parentID>/e?clone=1&retURL=<retURL>&<fieldname>=<parentID>)
 
 
***  How can I get the ID of the parent opportunity in the trigger ??????  ****
 
Kindly provide me a solution..
Thanks in advance,
Krishna
mba75mba75
Hi

I use the following opportunity trigger after insert to update the opportunitylineitem record of a specifique opportunity :


trigger opportunity_after_insert on Opportunity (after insert) {

Opportunity[] opps=Trigger.new;
opportunity_clone.Opp_line_item_del(opps);
}


 This trigger call opportunity_clone.Opp_line_item_del

public class Opportunity_clone {
public static void Opp_line_item_del(Opportunity[] opps){

List<OpportunityLineItem> updatedoli = new List<OpportunityLineItem>();


for (OpportunityLineItem oli : [SELECT Quote_Reference__c,ServiceDate,Provisioning_Type__c, Document_Type__c, Non_Verified_Contract__c,FROM OpportunityLineItem WHERE Opportunityid in :opps]) {
oli.Quote_Reference__c= null;
oli.ServiceDate= null;
oli.Provisioning_Type__c= null;
oli.Document_Type__c= null;
oli.Non_Verified_Contract__c= False;

updatedoli.add(oli);
}

update updatedoli;
}

}
I still have an issue my test method does not execute the iteration on the opportunity line item.

When I use my clone button the trigger is execute after the opportunityline item . but with my test method :

insert the opportunity then call my trigger ( when there is no opportunitylineitem ) and then it insert the opportunity line item .

So test covarage result is 17 %