[SalesForce] Standard Clone Button – Setting Field Values – Custom Button Or Something Else

Need: Ability to Clone records, and set a value into a field during the cloning. In my specific case, I want to populate either a Lookup field with the ID of the record cloned from (so passing forward SFID to the new record) or perhaps a URL field similarly.

Currently: My standard for what this would be to create a java-button that performs the clone manually, and fills in any fields during the process.

Any thoughts?

  • Can I "intercept" the clicking of the standard CLONE button and cause some fields to be populated with certain values (unless overwritten during the editing of the new record)?

  • Or do I just need to do the java-button?

  • Or is there something even better I'm not considering?

Thanks! In my case, this is on a Custom Object, if that matters (I doubt it).

Best Answer

You'd want to use sObject clone(true, false, true, true) where true preserves the existing Id, timestamps, and any autonumber fields), then assign the new value to the field you want to change before doing your save for the update. You could call this from a button, a before insert trigger or page controller or however you wanted.