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
VPROKVPROK 

Problem with getCloneSourceId().

Hi, guys.

I have a strange problem here, which really pisses me off :(

So it is very simple, just typing in execute anonymous:
Account acc;
acc.getCloneSourceId();

Gives me an error:
"Compile error at line 2 column 1
Method does not exist or incorrect signature: [Account].getCloneSourceId()"

According to this (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm)article, this method should work with any SObject, but it doesn't work with any object...
Please, tell me what am I missing.



Thanks!
Best Answer chosen by VPROK
VPROKVPROK
I have one though actually. Maybe it is Winter 16 feature.
Does anybody used it before? :)

All Answers

VPROKVPROK
even the example for this article is giving me the same error!
VPROKVPROK
I have one though actually. Maybe it is Winter 16 feature.
Does anybody used it before? :)
This was selected as the best answer
VPROKVPROK
it is from winter 16 =)
Tarun_KhandelwalTarun_Khandelwal
Hi,

It is working fine. Try this code -
List<Account> accList = [select Id from Account limit 1];
//system.debug(a[0].getCloneSourceId());
system.assertEquals(null, accList[0].getCloneSourceId());
VPROKVPROK
nope, the same. probably you have api 35 already :)
YES! definitely. Just tested in lightning ready org - working fine.
Looks like I will just have to wait for a couple of days
Lawrence-AccentureLawrence-Accenture
Does getCloneSourceId() only work once a record is saved? I'm trying to detect a record cloned in the UI during a before insert trigger and getCloneSourceId() is returning null.
Douglas C. AyersDouglas C. Ayers
@Lawrence, there is a known bug in Lightning Experience where the apex method getCloneSourceId() and the workflow function ISCLONE() return null. However, if you clone records from Classic UI then they behave as expected.

In a Spring '17 pre-release dev org (API v39), I just tested a contact "before insert" trigger and the getCloneSourceId() is populated when cloning in Classic UI but null in Lightning Experience.

You can subscribe to the known issue here: https://success.salesforce.com/issues_view?id=a1p3A000000IYveQAG
Roger WickiRoger Wicki
I have a before insert and an after insert trigger. Both of them loop through the trigger.new Opportunities and with both of them getCloneSourceId() returns null when the execution was triggered through the UI. This is really bugging me because I built this whole new handler to make use of that and get rid of the old method with the self id field...
Lawrence CoffinLawrence Coffin
Roger, I found during testing a while back that getCloneSourceId() (and isClone()) doesn't work for Opportunities cloned through the UI. Seems to work with (some) other objects, just not with Opps. See https://developer.salesforce.com/forums/?id=906F0000000kHpXIAU
Roger WickiRoger Wicki
Hi Lawrence

Thanks for the input. Although this surely has to be classified as bug. A really annoying one. In my test classes I didn't perform the operation on the server directly, but used the sObject.clone() command, which basically should do the same. That's why I didn't see it immediately.
Lawrence CoffinLawrence Coffin
Yeah, I agree that it's a bug. I wrote Salesforce Support about it last July/August and after much back and forth finally got a note saying it had been logged by the dev team as a bug. But then the case was closed and I never got a follow-up on it. Unfortunately I no longer have access to that case but I'll see if I have a way to submit a new one. If you have a way to submit a case and want to try to follow up on it, my original case was #14236392.
Lawrence CoffinLawrence Coffin
Actually, looks like they created a Known Issue out of it: https://success.salesforce.com/issues_view?id=a1p3A0000001BbRQAU
Roger WickiRoger Wicki
I have a very weird error occurring now. I switched back to using a field called SelfId__c, which stores the Opportunity's ID as text. So once that record is cloned, also the SelfId__c is cloned and thus does no longer match the clone's ID. That way I was detecting and reacting on the clone operation. But since I did my changes to use getCloneSourceId() this field is just set to null in before and in after triggers. This is simply impossible. Worst is, it doesn't happen all the times. I have yet to find what kind of weird combination causes it. I have no workflow rules, validations or other handlers even referencing the field.

Does anybody have experience with field values getting set to null?
Lawrence CoffinLawrence Coffin
Roger, what do you mean "since I did my changes to use getCloneSourceId()"? Are you using that method to set SelfId__c?
Roger WickiRoger Wicki
Hi Lawrence

No. All of our Opportunities have the field SelfId__c filled with their own ID. So when I clone, technically, this field should be carried over to the cloned record. It isn't though for some of them, which makes detection literally impossible.
I would do all my necessary logic for detected clones and in the end update the clones to have their own ID in the SelfId__c field.