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
GobbledigookGobbledigook 

Save and Go To New Page

Hey all,

 

I am trying to figure out how to use a command button that will save a Visualforce Page, then open a new Visualforce page passing in Parameters for the new page to use. 

 

I know that I would use a controller extension on the first page and include the standard save component, but what would I do afterwards? This is the code for the commandbutton itself and the parameters to pass to the new page

 

 

<apex:pageBlockButtons >
<Apex:commandbutton value="Save and Add Call Attendee" Action="{!save}"><Apex:param name="Account" value="{!Call_Report__c.Account__c}"/><apex:param name="CallReport" value="{!Call_Report__c.Name}"/></apex:commandbutton>
</apex:pageBlockButtons>

 

 

And this is the save component.  How would I open a new page after the save?  Is it a simple PageReference call to the new VF page? Is there something much more complicated? 

 

 

public PageReference save()
    {
        PageReference CRsave = controller.save();
        //I imagine something else would go here...
        return CRSave;
    }

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ngabraningabrani

The save method needs to return the URL of the page that you want to redirect to. Lets say the Visualforce page that you want to redirect to is called /apex/nextPage, then the following code can be added to the Visualforce controller extension

 

public PageReference save()

{     

        PageReference nextPageURL = new PageReference('/apex/nextPage');
        nextPageURL.getParameters().put('parameterName','parameterValue');
        
        return nextPageURL;
}

All Answers

ngabraningabrani

The save method needs to return the URL of the page that you want to redirect to. Lets say the Visualforce page that you want to redirect to is called /apex/nextPage, then the following code can be added to the Visualforce controller extension

 

public PageReference save()

{     

        PageReference nextPageURL = new PageReference('/apex/nextPage');
        nextPageURL.getParameters().put('parameterName','parameterValue');
        
        return nextPageURL;
}

This was selected as the best answer
GobbledigookGobbledigook

Thank you for your reply.

 

I got this far, but for some reason the parameters still aren't passing correctly.  I tried hard coding some data to test the pass through, but it's not being received correctly, or so I'm guessing.  I'm getting a "Attempt to De-Reference null value" error message.

Here's the parameters being passed through:

 

public PageReference SaveAdd()
    {
        
        PageReference CRsave = Page.FD_CallAttendee;
        CRsave.getParameters().put('Account','TestAccount');
        CRsave.getParameters().put('CallReport','TestReport');
        CRsave.setRedirect(true);
        return CRsave;
    }

 

 

 

And on the Controller of the receiving page:

 

 

 public FD_CallAttendee(ApexPages.StandardController controller) 
    {
        CA.Attendee_Account__c = system.CurrentPageReference().getParameters().get('Account');
        CA.Call_Report__c = system.CurrentPageReference().getParameters().get('CallReport');
        
 }

 

 

And in the URL the parameters are there, but it's still giving me a null value error.  I even tried to change it to pass through the IDs themselves, but still no luck. 

 

What gives?

GobbledigookGobbledigook

I actually got this to work.  I had forgotten to instantiate the processes through the standard controller. Silly me.

 

Thanks again!