[SalesForce] Cannot load custom object records from Lightning Data Service due to Users Permissions

I'm struggling to load my custom object record using LDS and i got a object privilegies error :

You don't have access to this record. Ask your administrator for help or to request access.

I've checked :

  • User profile : OK (as System Administrator, i'm the custom object owner)
  • Sharing Settings: No sharing Settings configured
  • Roles: No roles configured

I"ve full access (READ/WRITE) to the object/field/record according to my user profile.

Below is myComponent.cmp code

<aura:component implements="lightning:actionOverride,force:hasRecordId,
                        force:appHostable">
<aura:attribute name="record" 
                type="Object" 
                description="The record object to be displayed"/>
<aura:attribute name="simpleRecord" 
                type="Object"
                description="A simplified view record object to be displayed"/>
<aura:attribute name="recordError"
                type="String"
                description="An error message bound to force:recordData"/>

<force:recordData aura:id="newRecordCreator"
                  layoutType="FULL"
                  targetRecord="{!v.record}"
                  targetFields="{!v.simpleRecord}"
                  targetError="{!v.recordError}"/>

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>



<!-- Display Lightning Data Service errors -->
<aura:if isTrue="{!not(empty(v.recordError))}">
    <div class="recordError">
        {!v.recordError}
    </div>
</aura:if>

and here myComponentController.js

({
doInit : function(component, event, helper) {
    // Prepare a new record from template
    component.find("newRecordCreator").getNewRecord(
        "TEST_ME__c", // sObject type (entityAPIName)
        null,      // recordTypeId
        false,     // skip cache?
        $A.getCallback(function() {
            var rec = component.get("v.record");
            var error = component.get("v.recordError");
            if(error || (rec === null)) {
                console.log("Error initializing record template: " + error);
            }
            else {
                console.log("Record template initialized: " + rec.sobjectType);
            }
        })
    );
}
}

Huge thanks for helping me with this issue!

PS: When i try loading a Standard object it works…

Best Answer

Finally i've found out what was missing. I just added the namespace to my custom object definition in the getNewRecord() method as below and it works :

  • myNamespace__TEST_ME__c

Maybe because i'm working on a managed package, i had to specify the namespace.

Anyway the error message from LDS component was not really specific in my case.