[SalesForce] Redirect user to custom detail page after record insert

I would like to redirect users from my custom visualforce 'New Record' page to custom detail page passing an ID parameter while doing so. The current behavior, after creating the record the user will be shown the normal salesforce record detail page.

I have constructed some code for this but I am not sure if its correct, the first issue I get is with the extension:

Expression must be a list type: SOBJECT:Service_Order__c at line 6
column 80

UPDATE:
Now page leads to the following issue

Error: Error occurred while loading a Visualforce page.

VF:

<apex:page showHeader="false" title="New Order" standardController="Service_Order__c" extensions="force_NewOrderLogic">
...
<apex:commandButton value="Create Order" action="{!save}" styleClass="btn btn-success" rerender="error,styledError,unstyledError"/> 

Apex (updated):

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);
        orderPage.setRedirect(true);
        return orderPage;
    }
}

Best Answer

You have one order record, so you don't need to use an index to retrieve the id. Just change it to order.id. You would use the [0] on a list of orders not a single order. Also, create a new order for inserting: Service_Order__c order = new Service_Order__c.

Related Topic