I created a custom checkbox in the opportunity box so that an email is sent out to the team whenever it is checked. Issue is that an email is sent out if someone clones that opportunity. Is there a way to reset the checkbox whenever the opportunity is cloned? So that it is not checked in the new cloned opportunity?
Create a workflow rule with evaluation criteria as when record is created and update the checkbox as unchecked via field update.
Disclaimer: We call these URL hacks because they are hacky.
- Go to the opportunity fields and go to the details page for your custom field
- Grab the ID for the field and store it somewhere for now
- Remove the clone button from the page layout. Create a new button and label it "Clone" (you can give it what ever api name you want).
- Make the content source for the button "URL"
In the forumla editor, add the following
Note, you can use this method to set the value of ANY field when cloning a record. You can also use URL hacks like this to send users to edit pages with pre-set field values or even when creating new records.
Note2, Lookup fields require a slightly different syntax:
idOfRecord should be the exact id of the record you want pre-populated and RecordNameField should be the value in the, you guessed it, record's name field (for a contact it would be first + lastname such as "John Smith").
Note 3, Standard fields have crazy ids if you want to pre-populate them youll have to look up the names. For instance, fields on case are something like case_1. They do not have 18 digit ids as custom fields do.
Note 4, The field needs to be on the page layout and editable by the user in order for this to work. If this is an issue then you'll need to use a workflow or trigger or something. The problem with those solutions is there is no "isCloned" field that you can get access to so you're more than likely going to use the logic on insert which has the potential to impact opportunities other than the one you are cloning. For instance, if I create an opp as an admin or via an import, Ill set the box to true. It will automatically be overridden and set to false which you may not want. Implementing an "IsCloned" checkbox would require using this very hack. It'd be silly to use the hack to implement a different checkbox just so you can avoid hacking this checkbox directly.
Note 5, you can test whether you have the right Ids or syntax by clicking the clone button, copying the URL into notepad, adding in the field updates and pasting it directly into your browser.
May be this solution is obvious but here it is.
As Santanu mentioned, create a workflow. This is better as you can get all done with configuration and no coding.
For whatever reason, if that is not applicable, create a before insert trigger and reset the flag if it is checked.