You need to sign in to do that
Don't have an account?
How to display the detail page after clicking on save in Visualforce?
hi
I have a custom controller in which i have placed the logic of the save method.
However after clicked on save i want to display the detail page of the newly inserted record to the user
How do i do it?
Any help would be appreciated
Thanks
I have a custom controller in which i have placed the logic of the save method.
However after clicked on save i want to display the detail page of the newly inserted record to the user
How do i do it?
Any help would be appreciated
Thanks
TRY THIS YOU WILL GET THE SOLUTION.
VISUALFORCE PAGE
<apex:page controller="accountdetailcon" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="Top" >
<apex:commandButton value="Save" action="{!saverecord}"/> <br/><br/>
</apex:pageBlockButtons>
Account Name <apex:inputText value="{!name}"/><br/><br/>
Phone <apex:inputText value="{!phone}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER
public class accountdetailcon {
public String name { get; set; }
public String phone { get; set; }
public PageReference saverecord() {
Account a = new Account();
a.name = name;
a.phone = phone;
insert a;
pagereference pr = new pagereference('/' + a.id);
return pr;
}
}
Regards,
sfdc beginner
All Answers
http://www.faqoverflow.com/salesforce/3907.html
Thanks for your reply..
I just wanted to know whether the above piece of code mentioned in ur link would work for custom controllers?
Thanks
private ApexPages.StandardController controller;
public SaveAndReturnController(ApexPages.StandardController controller)
{
this.controller = controller;
}
this thing is throwing error.i have used it this way:
public Product2 pro{get;set;}
private ApexPages.StandardController controller;
public OuterClass(ApexPages.StandardController controller)
{
this.controller = controller;
}
public PageReference save() {
controller.save();
PageReference view = controller.view();
return view ;
}
Try making these changes to your save method
public PageReference save()
{
PageReference cancel = controller.cancel();
controller.save();
return cancel;
}
I wonder ,how will it wrk?controller is an instance of ApexPages.standardController and my class is a custom controller
I might have misunderstood because of this part of your code
private ApexPages.StandardController controller;
public OuterClass(ApexPages.StandardController controller)
{
this.controller = controller;
}
If you have customised your Save method, and I assume you have written insert/ upsert/ update a record can you try
PageReference pRef= new new PageReference('/'+recordId);
pRef.setRedirect(true);
return pRef;
TRY THIS YOU WILL GET THE SOLUTION.
VISUALFORCE PAGE
<apex:page controller="accountdetailcon" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="Top" >
<apex:commandButton value="Save" action="{!saverecord}"/> <br/><br/>
</apex:pageBlockButtons>
Account Name <apex:inputText value="{!name}"/><br/><br/>
Phone <apex:inputText value="{!phone}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER
public class accountdetailcon {
public String name { get; set; }
public String phone { get; set; }
public PageReference saverecord() {
Account a = new Account();
a.name = name;
a.phone = phone;
insert a;
pagereference pr = new pagereference('/' + a.id);
return pr;
}
}
Regards,
sfdc beginner