+ Start a Discussion
prabhat jhaprabhat jha 

force:recordData getNewRecord() method LDS

Hello Devs,
Can anyone explain what  getNewRecord() on the force:recordData component, returns a Record object or a particular standard/Custom objects.
I have read the documentation which states below:
The doInit init handler calls getNewRecord() on the force:recordData component, passing in a simple callback handler. This call returns a Record object to create an empty contact record, which is used by the contact form in the component’s markup.
but on different scenario it returned different results although same markup and syntax used.
({
    onInit :function(component,event) {  
            component.find("service").getNewRecord( 
                "BoatReview__c", // sObject type (entityAPIName) 
                null,      // recordTypeId           
        		false,     // skip cache?           
            $A.getCallback(function() {
                    var rec = component.get("v.boatReview");
                    var error = component.get("v.recordError");
                    var boat=component.get("v.boat");               
                    if(error || (rec === null)) {                  
                    console.log("Error initializing record template: " + error);
                        return;
                    } else{ 
                        console.log("Record template initialized: " + rec.apiname);
                        //component.set("v.boatReviewRecord.Boat__c",boat.Id);                   
                        component.set("v.boatReview.Boat__c",boat.Id);
                    }
                    
            })        
        );
    }
})

Here rec.apiname returns undefined and when i used JSON.stringify(rec),it returns below result as it does not have apiName fieldIt misses apiname Field of record Objectwhile it returns contact when i execute similar code on Contact.code snippet below:
doInit: function(component, event, helper) {
    // Prepare a new record from template
    component.find("contactRecordCreator").getNewRecord(
    "Contact", // sObject type (objectApiName)
    null, // recordTypeId
    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);
    return;
    }
    console.log("Record template initialized: " + rec.apiName);
It returns Contact as apiname See Result of JSON.Stringfy(rec)
It returns Ref of record object with APIname fields
    })
    );
}
Please let me know if Question is not clear or my understanding is wrong.
I am really scratching my head with this behavior.
Thanks in Advance.