function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PatMcClellan__cPatMcClellan__c 

LDS input form overwriting previous record

I'm using LDS to create a new record -- it's a simple one field input. After input, the record is saved and the init handler for the component runs again, clearing out my {!v.Message} attribute -- I have verified that this new record is "empty". However, when I enter a new message, it is overwriting the previously saved record instead of creating a new record.

Do I need to do a full reload (instead of a refreshView) of the component to get a fresh new record? If so, the docs are not clear on that process (see code below). Specifically, does this go in the Controller for the component I'm refreshing? If so, then what's the 'c.myController' reference? 
refresh : function(component, event, helper) {
    var action = cmp.get('c.myController');
    action.setCallback(cmp,
        function(response) {
            var state = response.getState();
            if (state === 'SUCCESS'){
                $A.get('e.force:refreshView').fire();
            } else {
                 //do something
            }
        }
    );
    $A.enqueueAction(action);
}

 
Best Answer chosen by PatMcClellan__c
PatMcClellan__cPatMcClellan__c
Found the answer here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_create_record.htm):

It's the 3rd param of the getNewRecord() method, commented in the docs as "skip cache?". I had to set it to true so that the subsequent new records would not be pulled from the existing record in the cache. I think that's what's going on -- it works now.
component.find("service").getNewRecord(
                "Message__c", // sObject type (entityAPIName)
                null,      // recordTypeId
                true,     // skip cache?
                $A.getCallback(function() {
                    var Message = component.get("v.Message");
                    var error = component.get("v.recordError");
                    if(error || (Message === null)) {
                        console.log("Error initializing record template: " + error);
                    }
                    else{
                        console.log("Message template initialized: " + JSON.stringify(Message));
                    }
                })
            );