Hi I'm having an issue with trying to create a save button on a custom VF page that saves the child record that's being created by the user and then redirects back to the parent record detail, which is where the VF page is linked from. I've tried so far to modify the extension with a method to call that would perform the desired function, but that hasn't worked. Here's my extension:
public with sharing class CreateAdditionalPayeeExtension {
Payee__c payee {get;set;}
private ApexPages.StandardController stdController;
//constructor
public CreateAdditionalPayeeExtension(ApexPages.StandardController stdController){
this.stdController = stdController;
payee = (Payee__c)stdController.getRecord();
payee.Order__c = ApexPages.currentPage().getParameters().get('ordId');
}
public PageReference saveAndReturn()
{
PageReference cancel = stdController.cancel();
stdController.save();
return cancel;
}
}
Please ignore the second and third lines in the constructor because those are used to autofill a lookup field on the page (works correctly). So in my VF inline editor, I've declared the extension, and the button's line is this:
<apex:commandButton action="{!saveAndReturn}" value="Save" />
When I click the save button to test it out, it saves the child record successfully but just redirects to the home page. I've tried all sorts of solutions that I've seen online, but none of them have worked properly or have been too complicated for me to modify into a working solution. Any help is greatly appreciated! Thanks in advance!