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
Jennifer Munoz, ERIJennifer Munoz, ERI 

Error when using force:recordData to prefill fields on lightning:recordEditForm

Hi,
I am getting the error "Received unexpected value during emit" when trying to prefill lighting:recordEditForm inputFields with data from force:recordData. The fields prefill, but I am unable to save the record. I was using this Trailhead as a reference: https://trailhead.salesforce.com/en/modules/lightning_data_service/units/lightning_data_service_manipulate_records

Received unexpected value during emit.
Code: 

<aura:component implements="force:lightningQuickActionWithoutHeader,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="CT" type="Asset"/>
    <force:recordData aura:id="record"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetRecord="{!v.record}"
                      targetFields ="{!v.CT}"
                      mode="VIEW"/>                                    
    
    <lightning:card iconName="custom:custom18" title="New Monthly Follow Up">
        <lightning:recordEditForm objectApiName="ERIDT1__Forms_Documents_Evaluations__c"
                                  recordTypeId="01261000000X0U2AAK">
            <lightning:messages aura:id="messages"/>
            <lightning:inputField fieldName="ERIDT1__Client_Tracker__c" value="{!v.recordId}"/>
            <lightning:inputField fieldName="ERIDT1__Dog__c" value="{!v.CT.ERIDT1__Dog__c}"/>
            <lightning:button class="slds-m-top_small slds-button slds-button_brand" type="submit" label="Save"/>
        </lightning:recordEditForm>
    </lightning:card>
</aura:component>
Best Answer chosen by Jennifer Munoz, ERI
Jennifer Munoz, ERIJennifer Munoz, ERI
Thank you. I had actually posted my question on StackExchange as well and got a response to move the Save button outside the recordEditForm and add an action to it which worked. So here is the code that works as a workaround for other people having the issue
Component:
...
        <lightning:recordEditForm objectApiName="ERIDT1__Forms_Documents_Evaluations__c"
                                  recordTypeId="01261000000X0U2AAK"
                                  aura:id="evaluationForm" 
                                  onload="{!c.onLoad}">
            <lightning:messages aura:id="messages" class="slds-hide"/>
            <lightning:inputField fieldName="ERIDT1__Client_Tracker__c" value="{!v.recordId}"/>
            <lightning:inputField fieldName="ERIDT1__Dog__c" value="{!v.CT.ERIDT1__Dog__c}"/>
        </lightning:recordEditForm>
    <lightning:button class="slds-m-top_small" variant="brand" type="button" name="update" label="update" onclick="{!c.saveRecord}" />
...

Controller JS:
({
    onload : function(component,event,helper) {
       var errorParamsRaw = event.getParams();
       var errorParamsJSON = JSON.stringify(errorParamsRaw);
       console.log(errorParamsJSON);
       if (!errorParamsJSON.includes("Received unexpected value during emit"))
            $A.util.removeClass(component.find("messages"), "slds-hide");    
  
    },
    saveRecord : function(component,event,helper) {
        component.find("evaluationForm").submit();
    }
})

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

Refer below link from StackExchange for similar discussion.

https://salesforce.stackexchange.com/questions/221690/lightningrecordeditform-received-unexpected-value-during-emit-error-on-loadin/221914
 
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya
 
 
Jennifer Munoz, ERIJennifer Munoz, ERI
Thank you. I had actually posted my question on StackExchange as well and got a response to move the Save button outside the recordEditForm and add an action to it which worked. So here is the code that works as a workaround for other people having the issue
Component:
...
        <lightning:recordEditForm objectApiName="ERIDT1__Forms_Documents_Evaluations__c"
                                  recordTypeId="01261000000X0U2AAK"
                                  aura:id="evaluationForm" 
                                  onload="{!c.onLoad}">
            <lightning:messages aura:id="messages" class="slds-hide"/>
            <lightning:inputField fieldName="ERIDT1__Client_Tracker__c" value="{!v.recordId}"/>
            <lightning:inputField fieldName="ERIDT1__Dog__c" value="{!v.CT.ERIDT1__Dog__c}"/>
        </lightning:recordEditForm>
    <lightning:button class="slds-m-top_small" variant="brand" type="button" name="update" label="update" onclick="{!c.saveRecord}" />
...

Controller JS:
({
    onload : function(component,event,helper) {
       var errorParamsRaw = event.getParams();
       var errorParamsJSON = JSON.stringify(errorParamsRaw);
       console.log(errorParamsJSON);
       if (!errorParamsJSON.includes("Received unexpected value during emit"))
            $A.util.removeClass(component.find("messages"), "slds-hide");    
  
    },
    saveRecord : function(component,event,helper) {
        component.find("evaluationForm").submit();
    }
})
This was selected as the best answer