Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
Hi Gurus,

i've created a VF and Apex page to display a form on a Site that is linked to a custom object in Salesforce. After the form is completed, the user is then redirected to my website. 

However, how can I add a "Thank you, you have successfully submitted the form" page before the user is redirected to my website? 

Please if you have an idea of how this can be achieved, please let me know.

This is my visualforce page: 

<apex:page standardController="Turndown__c" sidebar="false" showHeader="true" extensions="extencntrl" >

    <apex:form >

           <apex:pageBlock title="Documented Turndowns" id="turndown_list">

                

             <apex:pageBlockSection columns="1" >

                 

                

                 <!-- to remove the header, but keep the fields' help texts -->

                 <style type="text/css">

                     .bPageHeader {display: none;}

                     </style>

              

                 

            <!-- Inputfields --> 

            <apex:inputfield value="{! Turndown__c.Account__c }"/>

            <apex:inputfield value="{! Turndown__c.Phone_Number__c }"/>

            <apex:inputfield value="{! Turndown__c.Region__c }"/>

            </apex:pageBlockSection>

            

                        <apex:pageBlockButtons >  

                                <apex:actionStatus id="go">

                                    <apex:facet name="stop">                  

                                        <apex:commandButton value="Save" action="{!Save}" status="go" disabled="false" rerender="go"/>

                                                </apex:facet>

                                                <apex:facet name="start">

                                       <apex:commandButton status="go" value="Saving..." disabled="true" />

                                    </apex:facet>

                                </apex:actionStatus>

                        </apex:pageBlockButtons>       

             

                 </apex:pageBlock>

    </apex:form>

</apex:page>

apex code:

public with sharing class extencntrl{

    

    Turndown__c turnd;

    public extencntrl(ApexPages.StandardController controller) {

        this.turnd= (Turndown__c)controller.getRecord();

    }

    

    public pageReference save()

        {

            Insert turnd; // steps to save your record.

            Pagereference pgref = New PageReference(Label.WebsiteURL);

            return pgref;

        }

}

Thank you very much!
12 answers
  1. Nov 29, 2017, 10:03 AM
    Hi Ola Bamidele,

    Try Changing the Save method to this. It is working fine in my Org. 

    public PageReference Save() {

              PageReference detailPage = sc.Save();

            if (detailPage != null) {

                PageReference editPage = new PageReference(Label.websiteurl); 

                return editPage ;

            } else {

                return detailPage;

            }

        }

    Note:  When you will give the website Url in Custom Label, give the complete link. Eg :  

    http://www.google.com

    Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

    Regards ,

    Suraj
  2. Nov 28, 2017, 5:51 PM

    Hi Ola Bamidele,

    I have made the change in your code and it is working fine in my Org.

    VisualForce Page :

     

    <apex:page standardController="Turndown__c" sidebar="false" showHeader="true" extensions="extencntrl" >

    <apex:form >

    <apex:pageBlock title="Documented Turndowns" id="turndown_list">

    <apex:pageBlockSection columns="1" >

    <style type="text/css">

    .bPageHeader {display: none;}

    </style>

    <apex:inputfield value="{! Turndown__c.Account__c }"/>

    <apex:inputfield value="{! Turndown__c.Phone_Number__c }"/>

    <apex:inputfield value="{! Turndown__c.Region__c }"/>

    </apex:pageBlockSection>

    <apex:pageBlockButtons >

    <!--<apex:actionStatus id="go">

    <apex:facet name="stop">

    <apex:commandButton value="Save" action="{!showPopup}" status="go" disabled="false" rerender="go"/>

    </apex:facet>

    <apex:facet name="start">

    <apex:commandButton status="go" value="Saving..." disabled="true" rerender="tstpopup"/>

    </apex:facet>

    </apex:actionStatus>-->

    <apex:commandButton value="Save" action="{!showPopup}" status="go" disabled="false" rerender="tstpopup"/>

    <apex:outputPanel id="tstpopup">

    <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>

    <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">

    Thank you, you have successfully submitted the form <br/><br/><br/>

    <apex:commandButton value="Close" action="{!Save}" rerender="tstpopup"/>

    </apex:outputPanel>

    </apex:outputPanel>

    </apex:pageBlockButtons>

    </apex:pageBlock>

    </apex:form>

    <style type="text/css">

    .custPopup{

    background-color: white;

    border-width: 2px;

    border-style: solid;

    z-index: 9999;

    left: 50%;

    padding:10px;

    position: absolute;

    width: 500px;

    margin-left: -250px;

    top:100px;

    }

    .popupBackground{

    background-color:black;

    opacity: 0.20;

    filter: alpha(opacity = 20);

    position: absolute;

    width: 100%;

    height: 100%;

    top: 0;

    left: 0;

    z-index: 9998;

    }

    </style>

    </apex:page>

    Apex Class :

    public with sharing class extencntrl{

    private ApexPages.StandardController sc;

    public extencntrl(ApexPages.StandardController sc) {

    this.sc = sc;

    }

    public boolean displayPopup {get; set;}

    public void closePopup() {

    displayPopup = false;

    }

    public void showPopup() {

    displayPopup = true;

    }

    public PageReference Save() {

    PageReference detailPage = sc.Save();

    if (detailPage != null) {

    PageReference editPage = new PageReference(detailPage.getUrl() + '/e');

    return detailPage ;

    } else {

    return null;

    }

    }

    }

    Screenshot :

    User-added image

    User-added image

    User-added image

     

    Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

    Regards ,

    Suraj
  3. Dec 20, 2017, 8:45 AM
    Hi Suraj Tripathi, 

    Do you know how I can redirect to another visualforce instead of the "Label.Website" (which is a webpage)?

    Is it as simple as I will need to put the visualforce page name in the body of the labelI created?

    Or will I need to do something else aswell?

    Thanks
  4. Nov 30, 2017, 5:13 AM
    Thank you, Ola Bamidele for selecting my answer as best. It's my pleasure to help you.
  5. Nov 29, 2017, 2:46 PM
    Hi Suraj,

    Its now redirecting to the custom label as wantes.

    Thanks very much for the help.
  6. Nov 29, 2017, 8:25 AM
    Hi Suraj,

    Yes thanks the pop up is now working. However after the record is saved, the page is suppose to be redirected to the "Label.WebsiteURL" inside the the New PageReference. How can I add the "Label.WebsiteURL" to the code so that it will be redirected to the website after the record is saved? 

    Thanks very much!
  7. Nov 28, 2017, 1:33 PM
    Hi Suraj,

    Thanks for the reply but your code doesnt work. I firstly cant change my standard controller as that will could my form to stop working correctly. If you could make the additional changes to the original code I posted that would be great as youll understand better, thanks!
  8. Nov 28, 2017, 1:22 PM
    Hi Ola Bamidele,

    I have made few code changes. I have made a class with name  Accounttest.

    VisualForce Page :

    <apex:page controller="Accounttest">

    <apex:form >

    <apex:commandButton value="Show Pop up" action="{!showPopup}" rerender="tstpopup"/>

    <apex:pageBlock >

    This is just filler text from the Salesforce General.

    </apex:pageBlock>

    <apex:outputPanel id="tstpopup">

    <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>

    <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">

    This is where I would put whatever information I needed to show to my end user.<br/><br/><br/>

    <apex:commandButton value="Hide Pop up" action="{!closePopup}" rerender="tstpopup"/>

    </apex:outputPanel>

    </apex:outputPanel>

    </apex:form>

    <style type="text/css">

    .custPopup{

    background-color: white;

    border-width: 2px;

    border-style: solid;

    z-index: 9999;

    left: 50%;

    padding:10px;

    position: absolute;

    /* These are the 3 css properties you will need to change so the popup

    displays in the center of the screen. First set the width. Then set

    margin-left to negative half of what the width is. You can add

    the height property for a fixed size pop up if you want.*/

    width: 500px;

    margin-left: -250px;

    top:100px;

    }

    .popupBackground{

    background-color:black;

    opacity: 0.20;

    filter: alpha(opacity = 20);

    position: absolute;

    width: 100%;

    height: 100%;

    top: 0;

    left: 0;

    z-index: 9998;

    }

    </style>

    </apex:page>

    Apex Class :

    public class Accounttest {

    public boolean displayPopup {get; set;}

    public void closePopup() {

    displayPopup = false;

    }

    public void showPopup() {

    displayPopup = true;

    }

    }

    Screenshot :

    User-added image

    Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

    Regards ,

    Suraj
  9. Nov 28, 2017, 11:18 AM
    Hi Suraj Tripathi,

    Thanks for you response however when I enter the Outputpanel, I get an error saying:

    “Unknown property 'Turndown__cStandardController.displayPopUp”

     
  10. Nov 28, 2017, 11:17 AM
    Hi ChandanBiswas,

    Thanks for your response however I tried the code and it didn’t work – though it saved correctly.

     
0/9000