4

Wondering how to use the new defaultFieldValues parameter on the sforce.one.createRecord() method to pass in the parent or related records. The defaultFieldValues parameter is a Summer '17 feature that I am testing in a sandbox with Summer '17.

Documented here: https://releasenotes.docs.salesforce.com/en-us/summer17/release-notes/rn_vf_defaultfieldvalues.htm

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

I am trying to create a Task related to a record, and am trying to populate the Related To field, which is accessed via the whatID API Name:

Passed in as an Object:

var defaultsObj = {'Name' : 'Default', 'whatId','IDXYZ'}; 
sforce.one.createRecord('Object__c', myrecordTypeId, defaultsObj);

This doesn't seem to populate the Status or Priority fields on the Task record.

Passed in as an Array:

var defaultsArray = ['Status=Open', 'Priority=Normal','whatId=sfdcID']; 
sforce.one.createRecord('Object__c', myrecordTypeId, defaultsArray);

This also doesn't doesn't seem to populate the related record.

4 Answers 4

2

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

sforce.one.createRecord('Contact',null,{ 
    AccountId : "0010Y000007uaVI",  
});

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 contact is not Contact and only Contact is correct

1

From what I can see, this parameter is actually a Boolean that tells Salesforce to use your predefined field values that you have already set up for those fields.

For completeness, here is how you do that:

  • Click the name of an action in the Buttons, Links, and Actions list or the Global Actions list.
  • On the action detail page, click New in the Predefined Field Values list.
  • Select the field you want to predefine a value for.
  • Specify the value for the field.

This value can be calculated, so you have quite a lot of power to get a number of different values in here.

Ref is here

1

I was able to do this with the following:

var defaults = {'Name' : 'Default'};
sforce.one.createRecord('Object__c', myrecordTypeId, defaults);

And it's been working fine. I couldn't find documentation for it, just tried it and it worked as expected.

2
  • In your tests are you able to populate a lookup field? Specifically one like Related To on Tasks with an whatId? var defaults = {'Name' : 'Default', 'whatId','IDXYZ'}; sforce.one.createRecord('Object__c', myrecordTypeId, defaults);
    – Tate
    Jun 1, 2017 at 19:11
  • @Tate I haven't tried that yet.
    – sarakg
    Jun 2, 2017 at 19:56
0

Check that your API version of Visualforce page is at least 40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .