I currently have a controller extension + visualforce overriding the New button on an object. I'd like to to see if it's possible to reuse this for the Edit button as well.
If so, are there any design patterns or considerations in building this?
It is possible, but normally I don't do this based on personal preference. Generally speaking, there are different pieces of functionality that you are normally worried about when setting up an Edit or New page override. On top of that, New functionality will utilize an insert
while the Edit page will utilize an upsert
. You can get around that with an upsert
if needed.
I have had issues in the past where the two pages eventually become very different and then it becomes a pain to manage them. I normally export the logic needed into a service and then just call service methods inside my controller extension. This allows me to keep my functionality the same when necessary while still providing a different controller for each.
There are a few things to keep in mind when overriding standard buttons. However, with all of that said, if you think you will be fine using the same controller extension for both the New and Edit, you should have no problem doing that.