A Tip A Day #10 – ISCLONE in Trigger

This post is a part of the daily blog series 

A Tip A Day, daily dosage of learning!

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

 There you go! Be careful when using isClone while “cloning Opportunities without products“.
Unfortunately, there is no work around yet for this bug in Salesforce.

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”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: