0

Update: isClone() formula and apex method are not working for me (see comments in this post) I was thinking to use before Apex and a Validation Rule (below, not working). Would you solve this differently?

trigger ... on Account (before insert) {
    for (Account acc : Trigger.new) {
        if (acc.isClone()) { //does not work, known issue? https://success.salesforce.com/issues_view?id=a1p3A0000001BbRQAU
            acc.isCloned__c = TRUE; //a custom field to track which records are cloned
            acc.some_text_field__c = null; // requirement is that when cloning records using the standard clone button we want the user to acknowledge (be aware and fine with) the value of some_text_field__c before saving the record

        }
    }
}

Validation Rule on Account: Condition: If(AND(isCloned__c,isblank(some_text_field__c)),true,false) Error message: "You must provide a value in some_text_field__c before you can save a cloned record."

  • It sounds like you're attempting to enforce a rule that one specific field must hold different values between the original and clone record. Is that right? If that's the case, then this is impossible to accomplish using the standard clone button because you need something that's interactive. That is, you need to allow your user to first indicate that they want to clone the record, then (separate from the first action) allow them a chance to change the field (and display an error if they don't). Triggers and the standard clone button don't provide the level of interactivity that you need here – Derek F Nov 1 '17 at 15:34
  • That aside, if your suggested solution would be appropriate here, there is the ISCLONE() formula function. That could possibly eliminate the need for any code. – Derek F Nov 1 '17 at 15:38
  • Oddly isClone is not working for me in formula or apex. That is I don't get any field updates when doing this: help.salesforce.com/… Could be related to a known issue: success.salesforce.com/issues_view?id=a1p3A0000001BbRQAU I don't get field updates when trying the same in apex, either. That aside, i want to make sure the user knows and is ok with the value of 1 field during the cloning process. That is my true requirement. Maybe interactivity via JS is the right approach, or a box-check + VR.. – Peter Noges Nov 1 '17 at 15:43

Your Answer

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

Browse other questions tagged or ask your own question.