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
venkyyyvenkyyy 

Want to be stay on detail page itself, after click on save button.

Hi all, 
Please clarify my doubt,
My Question is: through controller i want to save account record, after saving perticular record i want to be stay on corresponding detail page itself.  Please see the bellow vf page and apex class and suggest me what i need to add to get detail page.
Thanks in advance,
venkat.

The Page is:
------------------
<apex:page controller="SaveAccount">
  <apex:form >
    <apex:pageblock title="Enter Account Details">
       <apex:pageblockSection >
          <apex:inputtext value="{!AcName}" label="Acc_Name"/>
          <apex:inputtext value="{!AcPhone}" label="Acc_Phone"/>
       </apex:pageblockSection>
       <apex:pageblockButtons location="Bottom" >
       <apex:commandButton action="{!Save}" value="Save"/>
       </apex:pageblockButtons>
    </apex:pageblock>
  </apex:form>
</apex:page>
----------------------------------
class is:
----------------------------------
public with sharing class SaveAccount {

    public PageReference Save() {
    account ac = new account();
    ac.name = AcName;
    ac.phone = AcPhone;
    insert ac;
        return null;
    }
    public String AcPhone { get; set; }
    public String AcName { get; set; }
}

 
ManojjenaManojjena
Hi vankat ,

Try to change the class code like below and let me know if it helps .
 
public with sharing class SaveAccount {
    public String AcPhone { get; set; }
    public String AcName { get; set; }
    public PageReference Save() {
    Account ac = new Account();
		ac.name = AcName;
		ac.phone = AcPhone;
		insert ac;
	PageReference pageref=new PageReference ('/'+ac.id);
		pageref.setRedirect(true);
		return pageref;
    }
}

Thanks 
Manoj
venkyyyvenkyyy
Thank you Manoj Its working fine,,

and can we have a clone buttone on detail page(i mean after saving a record we get detail page, on that detail page if i want to clone that record,)
JayantJayant
If your Use Case permits, try to use a Standard Controller on the Page with Extension instead of a Custom Controller.
Then you can make use of Clone() and View() methods from standard controller for cloning and redirecting to detail page respectively.
Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
Hi venkat,

There is no need to write code for cloning the record. You could simply enable the clone button on the page layout.