# Apex Trigger for Cloned Record - Values changing before and after insert

I have the following trigger for changing values when a record is cloned:

trigger oppAutomation on Opportunity (before insert) {
if(trigger.isBefore){
if(trigger.isInsert){
for (Opportunity o : trigger.New){
if(o.isClone() && o.StageName =='Closed Won'){
system.debug('Cloned Won Opp');
o.ClosedWonStage__c ='Pre-Approved';
system.debug(o.ClosedWonStage__c);
}
}
}
}

}


My issue is: In my test class after i clone a record the ClosedWonStage__c field takes the value of the record it was cloned from, As I expect.

While in the above trigger the ClosedWonStage__c value is set to 'Pre-Approved'

After the record is insert the ClosedWonStage__c value is resetting to the value of the original record.

Do I need to set the value of this field after the record is insert?

• whats the value you are getting in : system.debug(o.ClosedWonStage__c); – SFDC Learner May 16 '18 at 10:50
• system.debug(o.ClosedWonStage__c); - The value here is 'Pre-Approved' but then in my test class after I insert the Cloned Opp it sets back to the original record Value – denisoleary May 16 '18 at 14:01