You need to sign in to do that
Don't have an account?
Return from Save and Cancel buttons
My vf page, requestCreate, is working fine except for when the Cancel button is pressed the user is returned to the home page. I would like for the user to return to the requestCreate page.
I cloned the RequestNewExtension from an existing extension.
I have Save and Cancel buttons:
<apex:pageBlockButtons location="both">
<apex:commandButton value="Save" action="{!Save}" />
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
When the user chooses Save, I direct the user to a Thank You page, that works fine.
I tried different codes for the Cancel button unsuccessfully. I would like to return the user back to the requestCreate page
Here is my extenstion:
public with sharing class RequestNewExtension {
public String Comment
{
get;
set;
}
public String Description
{
get;
set;
}
public String Subject
{
get;
set;
}
public Boolean UseAssignmentRules
{
get;set;
}
public Case cs;
ApexPages.StandardController controller;
public RequestNewExtension (ApexPages.StandardController con)
{
controller = con;
this.cs = (Case) con.getRecord();
}
public PageReference Save()
{
CaseComment com = new CaseComment();
if(Comment.Length() > 0)
{
com.commentBody = Comment;
com.ParentId = cs.Id;
if(UseAssignmentRules == true)
{
AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
controller.getRecord().setOptions(dmlOpts);
}
insert com;
}
String retURL = ApexPages.currentPage().getParameters().get('retURL');
String CurrentId = ApexPages.currentPage().getParameters().get('id');
PageReference redirectPG;
if(retURL != null)
redirectPG = new PageReference('/' + retURL);
else if(CurrentId != null)
redirectPG = new PageReference('/' + CurrentId);
controller.Save();
return Page.Request_Create_Thankyou;
}
}
public PageReference Cancel(){
return null;
}
Is it not working?
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
public PageReference Cancel(){
return null;
}
Is it not working?
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Just override Cancel as you have done with Save.
Use PageReference to refer to desired page.
return new PageReference(path where you want to navigate)
I tried this in the past and got error messages.
I must have done something wrong.
Now I am returning to the calling page but the values I entered are still on the page.
How do I clear the page?
you have to set redirect as true
PageReference pageRef = new PageReference('partialURL');
pageRef.setRedirect=true;
return pageRef;
If you still see values then you can specifically set them as null in Cancel function.
My experience is:
Overriding the cancel action in a standard Controller extension allows you to customize the next page on Cancel. However, the user tends to expect to go back from whence they came