You can also do this using Flows and a custom Button. The flow must contain the following elements:
A variable that will store the initial record ID
An object variable that will hold the field information for the initial record.
A lookup element that finds the initial record and assigns it to the object variable.
A 'record create' element that creates a new Account record and lets you map the values from the object variable to the new record fields.
A 'record delete' element that deletes the initial record based on the ID variable
Finally, when you are satisfied with the flow, you can create a button on the Account object that references this flow through it's. You can also pass the Account ID in the url, and assign it to the ID variable that you created. A guide to doing this can be found here: https://help.salesforce.com/articleView?id=vpm_url_set_variable.htm&type=5
This method may be easier than implementing the process with Apex and Visualforce, however, it is completely possible to perform the same function with Apex. Please let me know if it is absolutely necessary to do so.
- A variable that will store the initial record ID
- An object variable that will hold the field information for the initial record.
- A lookup element that finds the initial record and assigns it to the object variable.
- A 'record create' element that creates a new Account record and lets you map the values from the object variable to the new record fields.
- A 'record delete' element that deletes the initial record based on the ID variable
Finally, when you are satisfied with the flow, you can create a button on the Account object that references this flow through it's. You can also pass the Account ID in the url, and assign it to the ID variable that you created. A guide to doing this can be found here: https://help.salesforce.com/articleView?id=vpm_url_set_variable.htm&type=5This method may be easier than implementing the process with Apex and Visualforce, however, it is completely possible to perform the same function with Apex. Please let me know if it is absolutely necessary to do so.