We have a lightning component that is initialized with an SObject from Apex. It then allows the user to make some changes to that SObject and send it back to Apex in another method for some processing. In the initial query for the object we include some related data that is required from our controller (for example, Owner.Name). If we send the SObject back to our Apex method with the related object still populated we get an error from the server:
Unable to read SObject
Previously, we had worked around this by executing the following prior to sending the record back to Apex:
The Apex method returns an updated version of the record with the related data back in there so there was no issue. However, after enabling Locker Service we are getting the following error when trying to delete the related data:
Cannot delete property 'Owner' of [object Object]
Is this by design? If so, Why would we be unable to modify objects that we created in this way? If we cannot delete object values and the fields on our objects are dynamic, what is the best practice for avoiding the "Unable to read SObject" error when our objects contain dynamic related data?
** Update **
I have narrowed the problem down further. The "Unable to read SObject" error only occurs when the object coming from Apex was initialized with
SObjectType.newInstance() after a result was not found via SOQL. This is also causing another issue where we are unable to populate fields on the record that did not initially have default values. I can see that the framework did not create
set() properties for most of the fields that we are then allowing users to populate in the UI. This results in the
lightning:input fields not being bound to the record correctly and no data being set.