Ok.
I have tried all the fixes listed:
Unable to read sObject error when saving Record From a Lightning Component's Controller
Lightning Components in Visualforce - Unable to read sobject
Unable to read SObject error in Lightning Component when record has been queried from the database
- set sobjectType = 'NS__ObjectName__c'
- set attributes = null
etc, etc, etc.
Anyone have any other ideas?
Some known facts:
The sObject is defined on the parent as:
<aura:attribute name="theObject" type="NS__APINAME__c" description="The sObject we will be working with"/>
(actual names removed to protect the innocent, it is a custom object from a managed package)
the sObject is retrieved from the apex controller with a lookup relationship populated with the ID of the appropriate record. It is instantiated in the apex controller as follows
return New NS__APINAME__C(LOOKUPFIELD__C = theId);
This sObject is passed into a child component as an attribute in the child component as such:
<aura:attribute name="theObject" access="public" type="NS__APINAME__C" required="true"/>
The controller on the child component
({
upsertObject : function(component, event, helper) {
var action = component.get("c.upsertTheObject");
var o = component.get("v.theObject");
//console.log(JSON.stringify(o));
o.sobjectType = 'NS__APINAME__C';
o.attributes = null;
action.setParams({
"obj": o //JSON.stringify(o)
});
action.setCallback(this, function(response) {
var state = response.getState();
if(state == "SUCCESS" && component.isValid()){
console.log("success") ;
}
else{
console.log("failed ::: " + response.getError()[0].message);
}
});
$A.enqueueAction(action);
}
})
- The method in the apex controller is set to a concrete sObject as the parameter
The only way I have been able to get this to work is by JSON.stringify.
Any one have any other ideas?
Apex method to get sObjectinstance
@AuraEnabled
public static NS__NAME__c getObjectInstance(String lookupId) {
return New NS_NAME__c(
Name = 'Test',
NS__LOOKUP__c = lookupId
);
}
Save method
@AuraEnabled
public static NS__NAME__c upsertTheObject(NS__NAME__c obj) {
//upsert theOrder;
return obj;
}
SoapBox I am not sure if it is the mindset coming from Apex/VF or not, but the most basic, simple, things in Lightning have been buggy, not working, difficult to implement, code bloat, etc. So far I am not impressed. I hope that the complex stuff is easier and offsets the steep curve with the basics. I mean cmon, I have to roll my own input for an sObject Picklist, code cannot be shared, loading does not work, can't save an sObject, can get something to eat, but only if x, y, and z are done, but you absolutely cannot do it if e or j is done first, e and j must be done last, then z, then you can eat. Oh my
And to top it off its 1 degree outside and I do not have any hats anymore...
I DO however love the automatic re rendering of the elements and updating of the values etc so far. that part is much easier End soapbox
AHHHHHHHHH
I just found out that unless you define the attribute with ALL fields you will be using or Query for them, no matter what you do in your controller the values will NEVER be set or passed to the apex controller. What a PITA. If I have an input that sets "{!v.theObject.Name}" it should set the name of the dang object. But I guess since it is JS Name will not be defined unless I define it so i guess I get it...