I am using sforce.one.createRecord('Contact') to create contact record and here i want auto populate some field including look up. is it possible ?

  • Have you seen this salesforce.stackexchange.com/questions/64850/… – Reshma Nov 30 '16 at 6:44
  • Probably I did understand the question wrong, but you could use var cont = new sforce.SObject("Contact"); And prepopulate needed fields by cont.LastName= 'MyLastName or cont.Account = accId – EvAzi Nov 30 '16 at 7:10

Now the answer is yes, you can! This feature to provide prepopulated field values was added by Salesforce in Summer'17 as described here: https://releasenotes.docs.salesforce.com/en-us/summer17/release-notes/rn_vf_defaultfieldvalues.htm

Now you can use it like this:

    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


No. If you read the documentation, you'll see that it accepts at most two parameters:

createRecord(​entityName​[, recordTypeId])

The recordTypeId parameter is in brackets, indicating that it is optional, and when not provided, uses the default mechanism for determining the record type to use (e.g, ask user or use default).

There's no other documented way of intentionally pre-populating fields, but for selected types, you can always use a Default Value formula. Unfortunately, lookup fields don't support default formulas.

If you want to provide default values, you'll still have to resort to "url hacks", which won't be supported by Salesforce1, but would work in the Salesforce Classic interface, or consider using a Flow or Lightning Component, which you could then pass parameters in by scripting.

  • Thanks for the clarification. Actually we are already using URL hacks for the classic interface and now we are going to support Lightning Experience interface and it's seems URL hack is not working in Lightning Experience interface. – Sagar Thoriya Nov 30 '16 at 7:01
  • @thoriyas Yes, unfortunately, URL hacks are a thing of the past. You might consider writing components that do the same thing, but that will require some work. I feel your pain; our company is transitioning to Lightning, too, and it'll require writing about 30-50 new Lightning Actions to move the entire company over. – sfdcfox Nov 30 '16 at 7:21

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.