I have a mobile app with two Objects which are linked via Master-Detail. I have overwritten the new page for creating an child record with an custom visualforce page.
This page should create an record with user entered data, and (after saving it) redirect to the parent Object.
I can't use the standard save action because of architectual reasons. So instead I use a save-button executing a "doSave" action in the controller extension and, on completion, redirecting with the "sforce.one" object to the parent object.
This works fine on "edit" but on the "new"-action the parent-Id parameter is missing.
Child__c = child Object
mdr_Parent__c = master-detail field on child
form = visualforce markup element to rerender
This is the Visualforce markup:
<!--BUTTON-->
<apex:outputPanel>
<center>
<apex:commandButton value="Save" action="{!doSave}" oncomplete="sforce.one.navigateToSObject('{!Child__c.mdr_Parent__c}');" rerender="form"/>
</center>
</apex:outputPanel>
And these are the controller extension constructor and method:
public Child__c child {get; private set;}
private ApexPages.StandardController stdCtrl;
// CONSTRUCTOR
public ExpenseCtrlExt(ApexPages.StandardController standardController) {
stdCtrl = standardController;
child = (Child__c) stdCtrl.getRecord();
}
public void doSave() {
try {
upsert child;
}
catch(Exception ignored){}
}
The button saves the record but does not redirect to the Parent record.
Thanks for helping.