This is more of an implementation question than code review.

I am currently using the 'clone' standard button that triggers changes on the new cloned record. However, I also have to mark the old record as having been cloned, or I'm looking to update a field in some way on the record.

I am aware that Trigger.oldMap() can be used for looking at old record values, but it can't update the old record field and give me a 'read only' error.

What is the best way to do this if not in the trigger I've already written?


Have a look at the sObject method getCloneSourceId().

Returns the ID of the entity from which an object was cloned. You can use it for objects cloned through the Salesforce user interface.

You can also use isClone() to see if you need to do the clone check first.

Returns true if an entity is cloned from something, even if the entity hasn’t been saved.

Once you have the ID of the record it was cloned from you can perform DML to update that record as required.

  • Can I do this in a trigger or would this logic be in a controller for use by a VisualForce page?
    – raisl
    Jan 8 '18 at 1:46
  • @raisl I assumed that the documentation statement that it would work for objects cloned via the SF UI implied it would work in triggers. Otherwise where else would you catch them? Might be best to do a quick test to confirm that assumption. Jan 8 '18 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.