+ Start a Discussion
Chitral ChaddaChitral Chadda 

redirect vf page

<apex:page standardController="Contact"   >
<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 wnat when i save this it should open like
/apex/MyFormContact?id=00190000010HAtb  and not        https://ap1.salesforce.com/00390000013dAX7
Best Answer chosen by Chitral Chadda
Grazitti TeamGrazitti Team
Hi Chitral,

Add Extension in the VF page like:

<apex:page standardController="Contact" extensions="custom_controller_name">

then create a Apex Class and override the save method like:
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;
}
}


let us know if you have any question .
please don't Forget to Mark this as your best answer if it works fine for you

Regards,
Grazitti Team
Web: www.grazitti.com

All Answers

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi,

You can write controller extension to overrride standard save method and redirect user to custom page.
This link might help you http://www.fishofprey.com/2012/03/using-standard-controller-save-method.html

Thanks,
N.J
Grazitti TeamGrazitti Team
Hi Chitral,

Add Extension in the VF page like:

<apex:page standardController="Contact" extensions="custom_controller_name">

then create a Apex Class and override the save method like:
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;
}
}


let us know if you have any question .
please don't Forget to Mark this as your best answer if it works fine for you

Regards,
Grazitti Team
Web: www.grazitti.com
This was selected as the best answer
Chitral ChaddaChitral Chadda
Error: Unknown constructor 'custom_controller_name.custom_controller_name(ApexPages.StandardController controller)'
i am getting this error

Chitral ChaddaChitral Chadda
not working
Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
This can also be useful i guess
<apex:page standardController="Contact">
<apex:form >
<script>
function Redirect()
{
    window.location="/apex/MyFormContact?id=00190000010HAtb";
}
</script>
<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}" onclick="{!Redirect}" value="save"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Grazitti TeamGrazitti Team
Hi Chitral,

This error is due to constructor. You didn't define a constructor in your controller. So please define constructor as follows in controller named custom_controller_name.

public custom_controller_name (ApexPages.StandardController controller) { 
      
    }

Regards,
Grazitti Team
Web: www.grazitti.com