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
phaniram satya durga upalapatiphaniram satya durga upalapati 

force:recordData SaveRecord method is throwing Error but still the record is getting updated.

My sharing settings for Opportunity Object is 'Private'. As part of my lightning component i am using force:recordData to read the record and update few fields i.e. OwnerId  to new User and saving the record. Issues is SaveRecord method is updating the record but it is returning error result.
Error: {"state":"ERROR","recordId":null,"error":[{"message":"The requested resource does not exist\n","pageErrors":[{"statusCode":"NOT_FOUND","message":"The requested resource does not exist"}],"fieldErrors":{},"potentialDuplicates":[]}],"entityApiName":null,"action":{}}. Kindly suggest me what might be the issue.

Component(.cmp):
---------------------------
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader" access="global">
    <aura:attribute name="recordId" type="string" />
   <aura:attribute name="record" type="Opportunity" />
  <!--Loading the Data from the Opportunity record -->   
    <force:recordData aura:id="editRecord" 
                              recordId="{!v.recordId}"
                              fields="['Name','RecordTypeId','OwnerId','Type']"
                              mode="EDIT"
                              targetFields="{!v.record}"
                              recordUpdated="{!c.dataLoaded}"
                              />
</aura:component>

controller.Js:
---------------
({
dataLoaded : function(component, event, helper) {
       // helper.fetchRec(component);
        let rec = component.get("v.record");
        rec.Type = '********';
        rec.OwnerId = '***************';
        component.set("v.record",rec);
   
},
})
helper.js:
-------------
({
    
    updateRec : function(component) {
             component.find("editRecord").saveRecord($A.getCallback((result) => {  
                    if (result.state == "SUCCESS" || result.state === "DRAFT") {
                        alert('success');                    
                    }else{
                       alert("Error: " + JSON.stringify(result));
                    }
        }
      ));
    },     
})
 
Raj VakatiRaj Vakati
Update the code as per below and try pls
 
component.find("editRecord").saveRecord($A.getCallback(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                        alert('success');                    
            } else if (saveResult.state === "INCOMPLETE") {
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                           JSON.stringify(saveResult.error));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        }));

 
phaniram satya durga upalapatiphaniram satya durga upalapati
HI Raj,
The solution did not help me as the State of SaveResult is always ERROR and i am seeing the same error message as mentioned in my Question.