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
Ian GoodineIan Goodine 

Class to open another visualforce page from an action button

I have a visualforce page (NCR View) embedded on an object layout (Non Conformance).  The visual force displays the relevant fields in detail view.  I made another VF page (NCR Edit) that shows the same fields in edit view.

I've created an "Edit" button on NCR View that is meant to redirect me to the NCR Edit page by calling the method OpenPage.  I will eventually create a save button on the NCR Edit that saves the info and brinds you back to NCR View.

When I click the edit button it redirects me to the new page but that page doesn't seem to really be associated to the fields in the object at all. Ideas?

My extension class: 
public PageReference OpenPage() {
        PageReference pr = new PageReference('/apex/Material_Nonconformity_Report');
        pr.setRedirect(true);
        return pr;
    }

Call to the method in NCR View:
<apex:commandButton value="Edit" action="{!OpenPage}"/>
Ajay K DubediAjay K Dubedi
Hi Ian,

Use bellow code for open another visualforce page from an action button it may helpful for you.
 
<apex:commandButton value="button" action="{!redirect}"/>

 public PageReference redirect() {
    PageReference pr = new PageReference('/apex/yourVFPageName');
    pr.getParameters().put('key','value');
    pr.setRedirect(true); 
    return pr;
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Ian GoodineIan Goodine
Thanks for the response Ajay, no luck though.  The way I can tell the association is not there is that the fields to be displayed in both the View and Edit VF pages are conditional based on a disposition field before that section.  That conditional formatting is successful in the embedded view page, but when I click edit it still does not occur (therefore no connection). I think Parameters command is the right direction though, thoughts?