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
Heather_HansonHeather_Hanson 

Apex Trigger onClick to trigger alert

Not sure if this is possible, but I want a trigger to fire when the Clone button on opportunity is clicked so that an alert will popup.  The alert is basic and the user can just click OK and move on to the standard clone create/edit page...I'd rather not override the standard edit page so that is why I'm hoping I can somehow achieve this in a trigger?

My trigger is below, but I'm thinking of all the actions available (before insert, after insert etc....) and none of them make logical sense so I'm not sure if what I want to do is possible. 

Worst case, I will just do it before insert, but the message will be telling them to NOT complete fields in the edit screen until after they save (loooong story) so it would be better for the user to get that message before they get to the edit screen.

Any help or suggestions would be appreciated!
 
trigger Clone_Popup on Opportunity (before insert) {
    for (Opportunity o : Trigger.new) {
  	if ( o.isclone() ) {
    o.addError('Warning...blah blah blah');
  }
}
}

 
Sunil Kumar Reddy Y 9Sunil Kumar Reddy Y 9
I dont think its possible, trigger executes the moemnt u click on save, you may have to consider custom clone to acheive this.
Heather_HansonHeather_Hanson
I was afraid of that!  Thanks!
Tom Connolly 2Tom Connolly 2
Any idea if the record created via Cloning has any unique characteristics?  What I'm looking to do is force a particular field to be manually changed.  Found this post and yeah the alert would help but I was thinking of using an after save flow to delete the field values, and send notificaiton to the creator to take a second look.  Was hoping there might be something I'm missing.  I have a few users in Classic so creating a custom clone button would be far more work imo