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
vijaynvijayn 

Overriding New/Edit/View with a single VF page. How do I detect each condition?

Hi all,

 

I'd like to override the New/Edit and View actions with the same VF page. Is this possible? If so, how do I detect when I'm in the 'new' mode, edit mode and view mode?

 

I can see that new gets passed a save_new=1 param. Is that the best indicator? what about View vs edit?

 

Any help is appreciated.

 

thanks,

Vijay

vijaynvijayn

To clarify the question more, in case it wasn't clear. I have a custom object for which I'd like to override the New/View/Edit actions etc. I'd like to use a single VF page to render all these actions. I need to detect when it's being called for a view vs. a new vs. an edit (so that I can render the appropriate functionality in the VF page (such as the detail vs. edit form)). What should I use to make the distinction? 

johutchjohutch

Hiya,

 

To distinguish between a new or edit vf page i use a map of the url parameters.

 

myMap=mypageref.getparameters();

 

 Once I have the url parameters, i do a search for a parameter of 'id'

 

if (myMap.get('Id') != null)

 If the id parameter is NOT specified, i know its a new record, if it is specified, i know its an edit of a record.

 

This works when i override the edit and new pages but I'm not sure how you would attack this for a view (since the id is specified in an edit and view).

 

 

BrianWKBrianWK

Does the URl contain a e? when it's being edited?

 

so if you pull the URL and parse for e? and the ID is present then it's an edit

if an e is present and no ID then it's a new

if an e is not present but the ID is then it's a view

vijaynvijayn

Right, I used the presence of the id (as well as the save_new param) for new vs (edit or view), but I can't distinguish between view/edit.

 

 

vijaynvijayn

BrianWK,

 

That doesn't work, as when I override an action, the system redirects so I am not at the 

 

/<ID>/e URL but at the /apex/<MyPage> URL.

 

 

thanks

Vijay

BrianWKBrianWK

Ahh, ok. I've overridden the New button on a few standard objects, and I've always ended up with extra parameters in my URL that I didn't put there.

 

 

I ended up having to create a new button to redirect to my VF page. I removed the standard "New" button and replaced it with my own list button. Then on that button I could pass any attribute I wanted to my hand typed URL.

 

This works great if you're only ever creating the object from a related list. If you're creating from the tab (like Cases) it doesn't work (can't figure out a way to remove the New Button that's not an override).

 

Unfortunately, since the edit button is on the object itself - it may not work for you. But it may be worth investigating if you can remove the buttons entirely and replace them with your own. Then you can put your own parameters in to distinguish between a New, Edit and View (with the New or Edit param missing).

vijaynvijayn

Hi BrianWK,

 

That's the conclusion I'd come to. Unfortunately this means I can't use any of the 'standard' components (if they put an action button such as new/save/edit) as those would redirect to the standard save/new/edit etc. :-(

 

 

Thanks for confirming though. Appreciate it.

 

Vijay