I get an error every time I try to set defaultFieldValues. There's no example of how to set it in the lightning data service docs. All I could find was example in the docs for force.createRecord but that's not helping much.

Here is the page I am referencing

Here is what it looks like when I tried to insert it into the doc's example of .getNewRecord:

        "Contact", // sObject type (entity API name)
        null,      // recordType Id
         'Name' : 'test Contact'
        false, // skip cache?
        $A.getCallback(function() {
            var rec = component.get("v.newContact");
            var error = component.get("v.newContactError");
            if(error || (rec === null)) {
                console.log("Error initializing record template: " + error);
            else {
                console.log("Record template initialized: " + 


The order of arguments in the docs says to put it after recordTypeId and before skip cache. The error I keep getting is

[type error on parameter callback: expected Function, found boolean]

So I'm guessing the ordering of arguments isn't right on the docs because it looks like it thinks the defaultFieldValues is the skipCache value and thus the skipChache value is the callback value. I've tried reordering several different ways but I can't get it. Perhaps I am making a syntax error Has anyone been able to use this yet?

  • Are you in Summer 17? Looks like the docs haven't updated the code sample, either. I'd report that as a bug on the feedback form. – sfdcfox Jun 2 '17 at 19:46
  • 2
    Thanks for the report. I've pinged the team that owns Lightning Data Service. Stay tuned for an update. – Kevin Venkiteswaran Jun 5 '17 at 3:29

I'm on the team that owns Lightning Data Service, and I can confirm this is a doc bug, and we're going to update it. While defaultFieldValues was a param of the getNewRecord() method in force:recordPreview, it is not available in the same method in force:recordData (which is currently in beta in Summer 17).

The code sample in the doc you linked to has an example of correct usage of getNewRecord(), where the four params are:

  • entityApiName
  • recordTypeId
  • skipCache
  • callback

Instead of setting defaultFieldValues in params of getNewRecord(), I'd recommend manually setting the values you need in the success case in the callback function you pass to getNewRecord(), so that it can be run after the record for create has been set into targetRecord.

  • Thanks! In the context of the callback function , will manually setting the default values to the the new targetFields attribute automatically set them to the targetRecord? – Mr. K Jun 6 '17 at 15:42
  • @Mr.K, yes, setting targetRecord.fields.[fieldName].value on targetRecord will be kept in sync with targetFields.[fieldName], and vice versa. – Carolyn Grabill Jun 6 '17 at 18:06

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.