Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
    
Seems to be the same problem described (and not answered) here: salesforce.stackexchange.com/questions/45745/… –  Robert Sösemann Aug 1 at 10:58

1 Answer 1

According to the docs:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_commandButton.htm

oncomplete only fires once an Ajax request is completed, whereas yours is a regular form postback. You'll need to add a rerender attribute to turn it into an Ajax request.

share|improve this answer
    
Sorry I had the rerender attribute in the button. Somehow I did not copy it in the browser. I'll change this. Still since I always had this attribute in the button, this can't be the reason why it's not working. After doing some debugging we found out that this "Parent Id" parameter is simply not transmitted to the VF page if you're using S1 on a mobile device. On the Desktop it's working fine. –  Robert Méndez Aug 1 at 10:28
    
Ah - are you relying on the parent id coming on the URL? You are correct, that isn't supported in SF1. –  Bob Buzzard Aug 1 at 11:27
    
any idea where this information is provided? If I hit save, the child record is saved to the correct parent, so somehow the id must be transmitted. –  Robert Méndez Aug 1 at 11:52
1  
I don't I'm afraid - just something I learned along the way. As you have the parent in the controller, can you not just make that available as a property? –  Bob Buzzard Aug 1 at 12:05
    
Sorry what do you mean by "you have the parent in the controller"? I'm using the Standard controller for Child__c. So I'm only able to get the child via StandardController.getRecord(). I could query the parent but I would need the parent id again. –  Robert Méndez Aug 1 at 12:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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