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> </div> <div class="row"> <div class="col-md-6 col-xs-12 text-right"> <a href="/force_Orders" rel="nofollow noreferrer noopener" class="btn btn-default">Cancel</a> <apex:commandButton value="Create Order" action="{!save}" styleClass="btn btn-success" rerender="error,styledError,unstyledError"/> </div> </div> </apex:form> </div> </apex:define> </apex:composition> </apex:page>
Extension:
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; } }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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; redirectPage.setRedirect(true); redirectPage.getParameters().put('id',controller.getId()); return redirectPage; } return null; }
Then change your action on the VF page to “saveAndRedirect”.
Reason:
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.
Method 2
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.
Method 3
We need to use pagereference class to navigate to record detail page.Go through the link below for same Page Reference Example
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0