function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DrawloopSupportDrawloopSupport 

Trigger from Clone event

I need to create a trigger that is kicked off when a custom object is cloned. Now I can do this via a before insert trigger on the object, but how would I know that the object is being clone vs a brand new record insertion?

 

It doesn't look like there is a "iscloned" method on triggers or sobjects. Does anyone have any ideas?

 

Thanks!

aalbertaalbert

What about a custom "Clone" button, that calls a Visualforce Page, which uses Apex (which has clone functionality built-in).

The Visualforce page doesn't have to much more than a simple page that says "In progress..." to notify the user of processing. And you can use the <apex:page> action attribute to call an apex method when the VF page loads. 

 

 

DrawloopSupportDrawloopSupport

I should have mentioned that I realize that is an option. It is, however, not a great solution, just a work around. I will probably have to implement it the way you have suggested.

 

Salesforce should be able to give us developers the functionality I am looking for, even if it is not currently available. I wanted to use the built-in functionality of the Salesforce clone and just build ontop of it.

AnthonyBAnthonyB

I'm faced with the same challenge, has there been any movement on this?

 

Would be nice to have the platoform tell us (developers) if trigger is being called as a result of a clone, (i.e. isClone)

marc.sofiamarc.sofia
Hi Drawloop Support. Here is what I would do:

Create a new custom field, say a checkbox, let's call it Clone__c. Default value is FALSE/unchecked.
Write your after insert trigger as follows:
if (Clone__c) {         //cloned record being inserted 
   whatever you wanted to do to cloned records
} else { 
    Clone__c=1 ;        //fresh record being inserted
}
Make sure any user profile that might be cloning records has write access to Clone__c.

Please don't forget to select "best answer" if this works for you.
Marc SofiaMarc Sofia
HI again, Drawloop support. I recently came across a very similar requirement and revisited this old thread and wondered if that had worked out for you. (If so, please don't forget to select best answer.)