You can add the nooverride
parameter to the page to get back to the normal page. Using your example URL:
https://na15.salesforce.com/500/e?nooverride=1&00Ni000000BGRVE=Communications&00Ni000000BGtUJ=Survey&00Ni000000BH0li=General%20Questions&cas8=Low&cas7=Closed&retURL=%2F500%2Fo
If you are using URLFOR
, you can also specify TRUE as the fourth parameter to include the nooverride
parameter. If you are using a PageReference
, you can add it as a parameter:
ref.getParameters().put('nooverride','1');
The value doesn't matter, by the way-- it doesn't have to be 1. It's just a convention that most developers use from what I've observed (because salesforce.com themselves use that value, and people copy examples).
URLFOR
has an optional fourth parameter that you can use. This forces the correct parameter for overriding any button override and showing the standard page. Here's an example that uses that (from the comments):
{!URLFOR($Action.Case.NewCase,null,['00Ni000000BGRVE'='Benefits','00Ni000000BGtUJ'='401K','00Ni000000BH0li'='General Questions','cas8'='High','cas7'='Open'],true)}
You can use general formula functions inside the third parameter to include things like TODAY()
or BR()
. Text concatenation should use the salesforce.com formula syntax: 'Edit ' & Name
might render as "Edit John Doe".
This will lead to a lot of conditionally rendered tags. You might consider having separate page for "view" and separate for "new/edit" but use same controller extension if you really want.
But if you're determined... You can look at the URL that was used to navigate to your page and combine it with presence of Id in the standard controller.
I've called my page override
and used Opportunity as the test object.
New: /apex/override?retURL=%2F006%2Fo&save_new=1&sfdc.override=1
View: /apex/override?id=0067000000AH3ME&sfdc.override=1
Edit: /apex/override?id=0067000000AH3ME&retURL=%2F006%3Ffcf%3D00B70000005pFQv%26rolodexIndex%3D-1%26page%3D1&sfdc.override=1
Something like this should work, at least until SF decides to rename/remove the retUrl
param (unlikely I'd say... Especially than on viewing there's rarely something to cancel or "on success return to... where?").
public MyExtension(ApexPages.StandardController ctrl){
Id i = ctrl.getId();
Map<String,String> parameters = ApexPages.currentPage().parameters();
if(i == null){
System.debug('new');
} else if(parameters.contains('retUrl')){
System.debug('edit');
} else {
System.debug('view');
}
}
Best Answer
You could achieve this by using the action propriety of apex:page
Create a new Visualforce page with only this line
override your edit button with this new page.
Don't forget to change the condition and the urls and to add your standard controller (SObject you want to override the Edit button for it) :)