Continuing from my previous post. I want to redirect the user to a custom vf detail page when they create a new Service Order from my custom page order page (force_NewOrder).

I have created a extension which should save and redirect the user but I am given a generic error:

Error: Error occurred while loading a Visualforce page.

VF (force_NewOrder)

<apex:page showHeader="false" title="New Order" standardController="Service_Order__c" extensions="force_NewOrderLogic">
  <apex:composition template="{!$Site.Template}">
    <apex:define name="body">  

    <h2 style="margin-top:0">New Order</h2>
    <div class="row">

          <apex:form styleClass="form" >
          <apex:pageMessages id="styledError"/>
          <apex:messages id="unstyledError"/>

          <div class="row">
            <div class="col-md-6 col-xs-12">

              <div class="row">
                <div class="form-group col-xs-12">
                    <label for="project-name">Project Name</label>
                    <apex:inputField value="{!Service_Order__c.Name}" required="true" styleClass="form-control" />


          <div class="row">
            <div class="col-md-6 col-xs-12 text-right">
              <a href="/force_Orders" class="btn btn-default">Cancel</a>
              <apex:commandButton value="Create Order" action="{!save}" styleClass="btn btn-success" rerender="error,styledError,unstyledError"/> 




public class force_NewOrderLogic {

    public force_NewOrderLogic(ApexPages.StandardController controller) {


    Service_Order__c order;

    public PageReference save() {
        insert order;
        PageReference orderPage = new PageReference('/force_OrderDetail?id=' + order.id);
        return orderPage;
  • Shouldn't your pagereference be ('/apex/force_OrderDetail?id=' + order.id) ?
    – Girbot
    Oct 7 '14 at 15:28
  • For force.com websites, using /apex/ isnt required Oct 7 '14 at 15:30
  • ah apologies =]
    – Girbot
    Oct 7 '14 at 15:32
  • Are you wanting your custom page to override the view for this object detail pages? If so, then there would be no need to parameterize the pageReference, just include the Id. /MYID
    – greenstork
    Oct 7 '14 at 15:43
  • @greenstork I would like the save function on my visual force page to redirect to a custom page, this is all on my force site. I would like the normal detail page to stay intact within SF Oct 7 '14 at 17:41

I found an answer here that might work for you as well, where the solution would be to change your "Save" method to the following:

public PageReference saveAndRedirect() {
  if(controller.save() != null) {
    PageReference redirectPage = Page.force_OrderDetail;
    return redirectPage;
  } return null;

Then change your action on the VF page to "saveAndRedirect".


1) Your "save" function is shadowed by the standard controller's "save" function, so your code won't work. You have to rename the function, and call that action instead.


Make sure that your force_OrderDetail page is visible in the portal, and accessible by the portal user. One way to test would be to take an existing orders ID, log into the portal and create the URL yourself, by appending /force_OrderDetail?id=xxxxxxxxxx to the end of the portal URL

Something like: https://myPortalcs11.force.com/force-OrderDetail?id=xxxxxxxxxxxx

Replace the xxxxx with a known good Order id that the portal user would have access to. If the page still fails, then the issue is not with your newOrder page, but with the OrderDetail page, or with the security related to it.

  • Yes the OrderDetail page definitely works and is open for portal users to see. I actually worked backwards and started on that first. Oct 7 '14 at 17:38

We need to use pagereference class to navigate to record detail page.Go through the link below for same Page Reference Example


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.