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
cirruscg1cirruscg1 

Using one VF page to override both View and Edit Actions??

How can I use ONE Visualforce page to override both VIEW and EDIT actions on a custom object?

 

I have a page written that will display an inputField in edit mode, and an outputField component in view mode -- but I can't find a way to determine if I'm in edit mode when the page is hit as a result of the edit action redirect. I've checked HTTP headers, hoping to find something like "/e?..." but there's nothing I can see that would be useful.

Best Answer chosen by Admin (Salesforce Developers) 
AhmedPotAhmedPot

Hi,

 

I just tried overriding view and edit button,

 

URL on click on view,

https://c.cs5.visual.force.com/apex/LoanDetailed_VF?id=006O0000001ro8B&sfdc.override=1


URL on click on edit

https://c.cs5.visual.force.com/apex/LoanDetailed_VF?retURL=%2F006O0000001ro8B&scontrolCaching=1&sfdc.override=1&id=006O0000001ro8B

 

we get retURL parameter when we click on edit, while its not there on view. so may be if you can use it to idntify which action is being performed.

 

Thanks,

Ahmed

All Answers

AhmedPotAhmedPot

Hi,

 

I just tried overriding view and edit button,

 

URL on click on view,

https://c.cs5.visual.force.com/apex/LoanDetailed_VF?id=006O0000001ro8B&sfdc.override=1


URL on click on edit

https://c.cs5.visual.force.com/apex/LoanDetailed_VF?retURL=%2F006O0000001ro8B&scontrolCaching=1&sfdc.override=1&id=006O0000001ro8B

 

we get retURL parameter when we click on edit, while its not there on view. so may be if you can use it to idntify which action is being performed.

 

Thanks,

Ahmed

This was selected as the best answer
cirruscg1cirruscg1

Thanks. Yeah, that works and seems to hold up in the scenarios I test. But it just seems fragile. :) I know users mess with URL params in custom buttons a lot, but I guess this will just have to be a "required" param for it to work right. Appreciate your help.