[SalesForce] Override Standard New button in Salesforce1

I have overridden the standard new button by calling the VF Page which takes me to the edit layout for a specific record type.

For ex: The controller on the VF page constructs a pagereference and returns.
new Pagereference('/'+Label.Object_Id+'/e?RecordType='+Label.RecordType_Id);

I have also set the NoOverride parameter to true.

When I try testing it from the Salesforce1 app, it lauches the app again on click of the overridden button.

Any thoughts on how the functionality be achieved in Salesforce1

Best Answer

Avoid using Pagereference methods in salesforce1 and usually i would prefer using @Remote action method to implement logic

Lets take a quick look with sample code below on how to achieve this

function actioninvoke(){
   if( (typeof sforce != 'undefined') && (sforce != null) ) {
   // Salesforce1 Remote Action method built in controller

   }
   else {
   //Action Function of normal App
   }
 }

Visualforce Code

 <apex:CommandButton value="Next" onclick="actioninvoke();" id="cmdNext" />

The advantages of remote action will be ability to callback and in callback we can use navigation specific function of salesforce1 like sforce.one

navigateToSObject(recordId,view)    //Navigates to an sObject record, specified by recordId.view is optional, and specifies the view within record home to select—chatter, related, or   detail.