1

We have a standard Clone and a standard DeepClone buttons on Opportunities and we'd like to do something different in the after insert trigger when the user presses the DeepClone button.

I can see that the opportunity was created from a clone in the trigger by using opportunity.isClone() but I can't distinguish between a regular clone or a DeepClone. I also inspected the populated fields map but it seems like both buttons produced the same data. Is there a way to determine which button was pressed in the trigger?

trigger OnOpportunity on Opportunity (after insert) {
    for(Opportunity opportunity: trigger.New){

       System.debug('isClone():' + opportunity.isClone());
       System.debug('getCloneSourceId():' + opportunity.getCloneSourceId());
            
       Map<String, Object> fieldsToValue = opportunity.getPopulatedFieldsAsMap();
     
       for (String fieldName : fieldsToValue.keySet()){
          System.debug('field name is ' + fieldName + ', value is ' + 
                        fieldsToValue.get(fieldName));
        }
    }
}
0

From the trigger's point of view, they are the same operation. You would need to have an Apex class set a static variable, then start the DML operation. The trigger could then check the variable to see if it's a deep clone or not.

1
  • Thanks @sfdcfox, that's what I was afraid of. – eduardo Nov 10 '20 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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