[SalesForce] Override “New” button auto populate not working in Salesforce1

I have overridden the 'New' button on Leads page to auto populate 'Owner' field for a specific business process that happens later. This works well in browser but not in the Salesforce1 App.we using "Professional Edition" Is there any reason for it?

Note:I checked also "Available for Salesforce mobile apps and Lightning Pages"

Please advise on this.

<apex:page standardController="Lead">

<script language="JavaScript1.2" src="/js/functions.js"></script>
<script src="/soap/ajax/9.0/connection.js" type="text/javascript"></script>
<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>

<script id="clientEventHandlersJS" language="javascript">
sforce.connection.sessionId = '{!$Api.Session_ID}';

console.log('!!!Name=');
var fname = '{!JSENCODE($User.FirstName)}';
var lname = '{!JSENCODE($User.lastName)}';
var name = fname+' '+lname;

if( (sforce.one != 'undefined') && (sforce.one != undefined) ) {
    sforce.one.navigateToURL('/00Q/e?lea21=1&nooverride=1&retURL=%2F00Q%2Fo&CF00N28000008YR6L_lkid='+window.UserContext.userId+'&CF00N28000008YR6L='+name+'',true); 
}
 else {
 console.log('!!web');
     window.top.location.href = '/00Q/e?lea21=1&nooverride=1&retURL=%2F00Q%2Fo&CF00N28000008YR6L_lkid='+window.UserContext.userId+'&CF00N28000008YR6L='+name+''; 
 }
</script>
</apex:page>

Best Answer

Plain and simple, you can use it like this one-liner:

sforce.one.createRecord('Lead',null,{ 
    FirstName : "John",
    LastName : "Doe",  
});

From the Summer '17 Release Notes - Prepopulate Fields on a Record Create Panel

Speed up record creation with prepopulated field values. The sforce.one.createRecord function now includes defaultFieldValues (optional) so you can define fields on a record create panel, including fields not displayed on the panel. This change applies to Lightning Experience and the Salesforce1 mobile browser app.

Users must have create access to prepopulated fields. Errors during saving that are caused by field access limitations do not display error messages.

Caution 1:

The this feature from Summer'17 works only if you put your Visualforce Page to API v40.0 or higher.

Caution 2:

Objectnames and Fieldnames are CASE-SENSITiVE! So lastname is not LastName and only LastName is correct

See also:

https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/salesforce1_dev_jsapi_sforce_one.htm

https://developer.salesforce.com/docs/atlas.en-us.208.0.lightning.meta/lightning/ref_force_createRecord.htm

Related Topic