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
Gareth MacCauleyGareth MacCauley 

Redirect after new Account

After I insert a new Account I want to redirect to a Visual Force page instead of the Account Details page.

Is this possible?
Sandeep YadavSandeep Yadav
Hi MacCauley
Use PageReference Method in your controller to redirect to another VF page.
Try this below code--
Controller--

public class MyExtension 
{
    public Account ac {get;set;}
    
    public MyExtension(ApexPages.StandardController controller) 
    {
        ac = new Account();       
    }
    
    public PageReference save()
    {
        insert ac;
        PageReference pg = new PageReference('/apex/VehicleInfo');
        pg.setRedirect(true);
        return pg;
    }

}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

VF Page--

<apex:page standardController="Account" extensions="MyExtension">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection >
              <apex:inputField value="{!ac.name}"/>
              <apex:inputField value="{!ac.rating}"/>
          </apex:pageBlockSection>
          
          <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlock>
  </apex:form>
</apex:page>
If this helps you, mark it as solved.
Thanks 
Sandeep
 
Waqar Hussain SFWaqar Hussain SF
Hi Gareth, 

This is not possible using Salesforce standard Account creation page. You will have to develop custom VF page and will have to override this VF page on new Account button to accomplish this requirement, as directed by @Sandeep.

Thanks
Gareth MacCauleyGareth MacCauley

Thanks all.

I'll go and do that and come back with a solved answer in a few days