0

I created a single Visualforce page that overrides default actions for almost all buttons for Event object. Actions are Edit, View, New Event, Accept and Decline. I need to detect the action in a controller which is associated with the Visualforce page.

Is there a way to do that? If yes, then how?

1
  • what do you mean detect the action? all action are different so every button has its own action so why you need to detect the action ? Jan 15, 2015 at 11:58

1 Answer 1

2

There's no way to discern whether the View action or the Edit action was used to visit your VF page. In both cases, the ApexPages.currentPage().getParameters() will contain just an 'id' attribute -- it will not be decorated with anything else.

The only solution is to create a separate redirect page for the Edit or View actions so that you can distinctly assign those pages as the overrides.

Your pages would have a page action similar to:

<apex:page standardController="MyObject__c" extensions="MyExtension" action="{!redirectToEdit}">

And the Apex would redirect:

public PageReference redirectToEdit(){
    PageReference ref = Page.MyObject;
    ref.getParameters().put('edit','true');
    return ref;
}

This question propose an alternative (using retUrl as your smell test for View vs. Edit, but I am suspect that it will work for all cases) How do I use the same Visualforce page to override view, new, and edit buttons on custom object

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .