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
vinny rvinny r 

Unable to create/update record using lightning data service

I am trying to update FinServ__AssetsAndLiabilities__c record using lightning data service. I am getting below error while trying to save record.

saving record, error: [{"fieldErrors":{"Id,Name":[{"message":"No access to field Id,Name. Either the field was removed from the entity or access to this field was removed.","fieldApiName":"Id,Name"}]},"pageErrors":[]}]


I have removed all the fields and using only Name, which is a required field. But still I am getting the error. I am able to create/update FinServ__AssetsAndLiabilities__c records using standard page.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vinny,

Greetings to you!

I request you please post the complete code snippet of what you have tried so that we can look into it and can help you accordingly. I believe there is something wrong in your code.

However, please try the below code to create a record using LDS. Kindly modify the code as per your requirement.

Component:
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordError" type="String"/>
    <aura:attribute name="recordInfo" type="Object" />
    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordId" type="String"/>

    <aura:handler event="force:refreshView" action="{!c.isRefreshed}" />
    
    <force:recordData aura:id="recordLoader"
                      recordId="{!v.recordId}"
                      layoutType="FULL"        
                      mode="EDIT"
                      targetRecord="{!v.recordInfo}"                        
                      targetFields="{!v.simpleRecord}"    
                      targetError="{!v.recordError}"
                      />
    
    
    
    <div class="slds-form--stacked">
        <div class="slds-form-element">            
            <div class="slds-form-element__control">
                <lightning:input label="Opportunity Name" value="{!v.simpleRecord.Name}" aura:id="accName"/>
            </div>
        </div>
        
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:input label="Stage" value="{!v.simpleRecord.StageName}" aura:id="accStage"/>
            </div>
        </div>
        
        <div class="slds-form-element">
            <div class="slds-form-element__control">
                <lightning:input label="Close Date" value="{!v.simpleRecord.CloseDate}" aura:id="accDate"/>
            </div>
        </div>
        <br/>
        <lightning:button aura:id="saveButton"
                          label="Save Button"
                          onclick="{!c.SaveOppor}">
        </lightning:button>
    </div>
</aura:component>

Controller:
({
    SaveOppor : function(component, event, helper) {
        component.find("recordLoader").saveRecord(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                // record is saved successfully
                
                var resultsToast = $A.get("e.force:showToast");
                resultsToast.setParams({
                    "title": "Saved",
                    "message": "The record was saved.",
                    "mode":"sticky"
                });
                resultsToast.fire();
                $A.get('e.force:refreshView').fire();
                
            } else if (saveResult.state === "INCOMPLETE") {
                // handle the incomplete state
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                // handle the error state
                console.log('Problem saving contact, error: ' + 
                            JSON.stringify(saveResult.error));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state +
                            ', error: ' + JSON.stringify(saveResult.error));
            }
        });
    },
    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },
})

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas