You need to sign in to do that
Don't have an account?
Rick SF Admin
Apex Code to redirect to another "Your profile has been submitted successfully" VF page.
I'm creating a VF page for employees to create a record for a custom object. I'm having issues writing the redirect Apex code so that after they hit "Submit", the employees will be redirected to another VF page (that I've created called "SuccessPage") that says "Your profile has been submitted successfully". After five seconds the SuccessPage it automatically redirect to the company's website. But if the employee hits Cancel, it will close the VF page.
Record Code
Record Code
<apex:page standardController="Object__c"> <apex:form > <div class="header"> <center><img src="{!$Resource.companylogo}" width="10%"/></center> </div> <style> body .bPageBlock .pbBody .blue .pbSubheader{ background-color:#154f82; } body .bPageBlock .pbBody .white .pbSubheader h3{ color:#ffffff; } </style> <apex:outputPanel styleClass="blue" layout="block"> <apex:pageBlockSection title="Skills" id="section7"> <apex:inputField value="{!Employee_Profile__c.Skills__c}"/> </apex:pageBlockSection> </apex:outputPanel> </apex:pageBlock> <center><apex:commandButton value="Submit" action="{!save}"/><apex:commandButton value="Cancel" action="{!cancel}"/></center> </apex:form> </apex:page>Success VF page
<apex:page > <h1>Success</h1> <script type="text/javascript"> window.setTimeout("redirectpage();", 5000); function redirectpage(){ window.top.location.href = 'http://www.website.com'; } </script> </apex:page>
<apex:commandButton value="Submit" action="{!save}"/>
But your method is called saveAndSuccess.
What's happening is that when you hit the save button it's calling the default "hidden" save method of the StandardController and ignoring your saveAndSuccess method.
Change to
<apex:commandButton value="Submit" action="{!saveAndSuccess}"/>
Add some System.debug in the saveAndSuccess method so that you can verify via logging that you're hitting that method.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_methods.htm
All Answers
- Use of PageReference: A PageReference is a reference to an instantiation of a page reference. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values like custom parameters or standard parameters for PageReference created.
- Please refer the below link for reference.
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_system_pagereference.htm
- https://developer.salesforce.com/forums/?id=906F0000000Al8PIAS
Let us know if it helps.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
<apex:commandButton value="Submit" action="{!save}"/>
But your method is called saveAndSuccess.
What's happening is that when you hit the save button it's calling the default "hidden" save method of the StandardController and ignoring your saveAndSuccess method.
Change to
<apex:commandButton value="Submit" action="{!saveAndSuccess}"/>
Add some System.debug in the saveAndSuccess method so that you can verify via logging that you're hitting that method.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_methods.htm