This post is a part of the daily blog series
Day #10 – ISCLONE in Trigger
Triggers work on events like Insert, Update, Delete, Undelete. There are requirements where you need to perform actions on Cloning of records too. Salesforce has the default method that checks whether the record is being cloned. The method is IsClone().
“isClone()” method returns boolean output True/False.
It returns True when checked for Cloning of any object.
Exception: “isClone()” method always return FALSE when doing opportunity clone “without copying opportunity product” mode.
Note: This issue applies to workflow as well.
Sample Trigger Code on Opportunity ================ trigger OppTestTrigger on Opportunity(before insert) { for (Opportunity opp: Trigger.new) { if (opp.isClone()) { System.debug('====> isClone: '+opp.isClone()); }else { System.debug('====> isClone: '+opp.isClone()); System.debug('====> getCloneSourceId(): '+opp.getCloneSourceId()); } } }
Expected result: all trigger logs should show “====> isClone: true”
Actual result: Opportunity trigger logs show something like the following
====> isClone: false
====> getCloneSourceId(): null
Read all other tips of the blog series here – A Tip A Day, daily dosage of learning!
One Reply to “A Tip A Day #10 – ISCLONE in Trigger”