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
Chitral ChaddaChitral Chadda 

redirect vf page

<apex:page standardController="Contact"  extensions ="custom_controller_name" >
<apex:form >
<apex:pageBlock title="Contact">
<apex:pageMessages />
<apex:pageBlockSection >
<apex:inputField value="{! contact.accountid}"/>
<apex:inputField value="{! contact.phone}"/>
<apex:inputField value="{! contact.FirstName}"/>
<apex:inputField value="{! contact.LastName}"/>
<apex:inputField value="{! contact.Fax}"/>
<apex:inputField value="{! contact.Email}"/>
<apex:inputField value="{! contact.title}"/>
<apex:inputField value="{! contact.phone}"/>

<apex:inputField value="{! contact.HomePhone}"/>
<apex:inputField value="{! contact.Department}"/>
<apex:inputField value="{! contact.Birthdate}"/>
<apex:inputField value="{! contact.MobilePhone}"/>



<apex:commandButton action="{! save }" value="save"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

when i save this  it goes to the standard page

i want that when i save this it should open like
/apex/MyFormContact?id=00190000010HAtb (view mode)  and not        https://ap1.salesforce.com/00390000013dAX7

apex: class

public class custom_controller_name{
public Contact contact {get;set;}
public pagereference save(){
try{
insert contact;
}catch(Exception e){}
Pagereference pref = new pagereference('/apex/MyFormContact?id=' + contact.id);
pref.setredirect(true);
return pref;

}
}
it gives error :Error: Unknown constructor 'custom_controller_name.custom_controller_name(ApexPages.StandardController controller)'
Best Answer chosen by Chitral Chadda
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Please modify your controller as
public class custom_controller_name{
	public Contact oContact {get;set;}
	ApexPages.StandardController sController;  
      
    public custom_controller_name (ApexPages.StandardController controller) {  
        sController = controller;  
        oContact = (Contact)controller.getRecord();  
    }  
	public pagereference save(){
		try{
			insert oContact;
		}catch(Exception e){}
		
		Pagereference pref = new pagereference('/apex/MyFormContact?id=' + oContact.id);
		pref.setredirect(true);
		return pref;

	}
}

If this answers your question, mark this as best answer.

Thanks,
N.J

All Answers

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Please modify your controller as
public class custom_controller_name{
	public Contact oContact {get;set;}
	ApexPages.StandardController sController;  
      
    public custom_controller_name (ApexPages.StandardController controller) {  
        sController = controller;  
        oContact = (Contact)controller.getRecord();  
    }  
	public pagereference save(){
		try{
			insert oContact;
		}catch(Exception e){}
		
		Pagereference pref = new pagereference('/apex/MyFormContact?id=' + oContact.id);
		pref.setredirect(true);
		return pref;

	}
}

If this answers your question, mark this as best answer.

Thanks,
N.J
This was selected as the best answer
Chitral ChaddaChitral Chadda
oContact = (Contact)controller.getRecord();

Wats is the use of dis statement