2

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.

2

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.

| 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 '14 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 '14 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 '14 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 '14 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 '14 at 12:36
0

Well after some years i got curious and recreated the situation. Seems like Salesforce must have fixed something. The exact code from above works fine now in S1 Desktop Simulators aswell as in actual Smartphone S1.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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