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
Yang WangYang Wang 

isClone() func does not work for cloning from UI

Hi Guys

when I am cloning from UI by clicking "clone" standard button, Its returning :false. On the other hand if I am doing it from APEX its returning " True".

lead c = new lead(id='00Q9000000xfFHVEA2');
lead cd = c.clone();
system.debug(cd.isclone());

USER_DEBUG|[5]|DEBUG|true

Does anyone know how to identify a new reocrds was cloned from UI in apex.
 
Prem Anandh 1Prem Anandh 1
Hi Yang,

We can maintain a checkbox field (isCloned__c) and when record is creating by cloned record we can make it the checkbox as True. Please see below code. 
 
lead l = [select id, firstname, lastname, company from lead where id = '00Q2800000HD3xA' limit 1][0];
lead l2 = l.clone(false, true);
l2.isCloned__c = true;
insert l2;
Please let me know if this way help you to fulfil your requirement

Thanks, 
Prem Anandh
 
Yang WangYang Wang
Hi Anandh

Thanks for your help. 
I understand your solution.
but I wonder how to distinguish a record was created by standard "clone" button.

Regards,
Yang
Lawrence-AccentureLawrence-Accenture
Yang, it appears the isClone() method only works for records cloned within apex. The same appears to be true for the getCloneSourceId() method. Neither method returns a value that indicates a record has been cloned in the UI in my testing. It's unfortunate.
Lawrence-AccentureLawrence-Accenture
Yang, a follow-up to my last post... I've done some testing and it looks like isClone() works for some objects but not others. For me, it appears to work for Accounts, Contacts and Leads, but not for Opportunities. Your code sample shows you were testing against Leads, is that correct? Is it working for you now? The trigger code I'm using to test leads is:
 
trigger TestIsCloneLead on Lead (before insert) {
    for (Lead rec: Trigger.new) {
        System.debug(LoggingLevel.ERROR, '====> isClone: ' + rec.isClone());
    }
}

 
Lawrence CoffinLawrence Coffin
The issue with cloning an opp from the UI and isClone()/getCloneSourceId() is now a Known Issue: https://success.salesforce.com/issues_view?id=a1p3A0000001BbRQAU