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
Steven Berg 5Steven Berg 5 

How can I redirect a user to a new VisualForce page using javascript remoting?

I am using Javascript remoting and after inserting a record would like to redirect the user to a new visualforce page
that displays the message "Contact record inserted".

Here is a snippet of my code:
In My Visualforce Page:

                      function(result, event) {
                        if (event.status) {

In My controller: After inserting a record would like to redirect the page with parameters being passed.

  global static PageReference AddUser(String txtCardHolderFirstName, String txtCardHolderLastName,
  String txtCardHolderDob, String txtCardHolderCity, String txtCardHolderState,
  String txtCardHolderZipCode, String txtCardHolderType, String recordid) {
                                              /* record gets inserted with passed arguments */
                                             /* would like to redirect the user  to a Visualforce page */

Pagereference pg = new Pagereference('/apex/AddUserWizardConfirmation');
                                                  pg.getParameters().put('NewCardHolderSalutation', NewCardHolderSalutation);
                                                 system.debug('Msg in Add User Wizard is ' + Msg);
SonamSonam (Salesforce Developers) 
Hi Steven,

​JavaScript remoting allows you to run asynchronous actions by decoupling the page from the controller and to perform tasks on the page without having to reload the entire page.

I tried your code and it should work if you try to redirect the page using javacript rather than doing it via the controller.

Try adding the redirect in your visualforce after this piece of code as shown below :

                      function(result, event) {
                        if (event.status) {

//redirect to the apex pages you want'/apex/AddUserWizardConfirmation?id=&NewCardHolderId=&NewCardHolderFirstName=&NewCardHolderLastName=&NewCardHolderSalutation=');