• Surabhi20
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
public void createSubexampleOnExample(List<ID> opportunityId, Map<ID,ID> oppLot){
        
        for(Id oppId : opportunityId){
            List<sub_Example__c> subExamples = new List <sub_Example__c>();
            List<Opp_Account_Relationship__c> acc = [Select Account__c, Opportunity__c from Opp_Account_Relationship__c where Opportunity__c =: oppId];
                
            for(Opp_Account_Relationship__c oppAcc : acc){
                sub_Example__c sub = new sub_Example__c();
                sub.Example__c = oppLot.get(oppAcc.Opportunity__c);
                sub.Account__c = oppAcc.Account__c;
                lotAccounts.add(sub);
            }
            insert subExamples;
        }
        
}

I am using isClone() in trigger handler for before insert and after insert scenarios on opportunity to execute some code only when opportunity is cloned. It is working fine except for in Test Class. 

My understanding is below code from TEST CLASS should work as Clone button on opportunity -
Opportunity op2 = op1.clone(false,true);
insert op2;

But in my handler isClone() is returning FALSE for after insert in test class and hence entire block of code is not getting covered.

Any suggestions on what I am doing wrong?
or any alternate approach to achieve this?

public void createSubexampleOnExample(List<ID> opportunityId, Map<ID,ID> oppLot){
        
        for(Id oppId : opportunityId){
            List<sub_Example__c> subExamples = new List <sub_Example__c>();
            List<Opp_Account_Relationship__c> acc = [Select Account__c, Opportunity__c from Opp_Account_Relationship__c where Opportunity__c =: oppId];
                
            for(Opp_Account_Relationship__c oppAcc : acc){
                sub_Example__c sub = new sub_Example__c();
                sub.Example__c = oppLot.get(oppAcc.Opportunity__c);
                sub.Account__c = oppAcc.Account__c;
                lotAccounts.add(sub);
            }
            insert subExamples;
        }
        
}

I am using isClone() in trigger handler for before insert and after insert scenarios on opportunity to execute some code only when opportunity is cloned. It is working fine except for in Test Class. 

My understanding is below code from TEST CLASS should work as Clone button on opportunity -
Opportunity op2 = op1.clone(false,true);
insert op2;

But in my handler isClone() is returning FALSE for after insert in test class and hence entire block of code is not getting covered.

Any suggestions on what I am doing wrong?
or any alternate approach to achieve this?