I have a lightning component (controller) that calls Apex to save a new record in my custom object, Conversation__c. This was working fine pre-namespace, but after moving to an org with a namespace, I've had to make some modifications.
For retrieving records, I'm using a wrapper class to strip the namespace from the fields, passing the un-namespaced fields from Apex out to Lightning. Got that working fine.
Now, I'm trying to save a new record, passing the Conversation__c record with un-namespaced fields to the @AuraEnabled Apex method saveConversation. Since Conversation__c fields now have the namespace appended, I'm creating a new Conversation__c record called newConversation, and assigning it the values from the Conversation I passed from Lightning -- at least that's what I am trying to do.
The values get passed into the Apex method ok, but after that, I can't seem to extract them from the object. Take a look at the code.
@AuraEnabled
public static Id saveConversation(Conversation__c Conversation)
{
System.debug('Conversation: ' + Conversation);
System.debug('Group Name: ' + Conversation.Group_Name__c);
System.debug('Case: ' + Conversation.Case__c);
System.debug('Opportunity: ' + Conversation.Opportunity__c);
System.debug('FirstName: ' + Conversation.FirstName__c);
System.debug('Conversation: ' + Conversation); // repeat
Conversation__c newConversation = new Conversation__c();
newConversation.Group_Name__c = Conversation.Group_Name__c;
newConversation.Case__c = Conversation.Case__c;
newConversation.Opportunity__c = Conversation.Opportunity__c;
newConversation.FirstName__c = Conversation.FirstName__c;
insert newConversation;
return newConversation.Id;
}
And here's my debug log:
16:51:41:003 USER_DEBUG [37]|DEBUG|Conversation: p7g180219__Conversation__c:{Group_Name__c=Tim Barr, FirstName__c=Tim}
16:51:41:003 USER_DEBUG [39]|DEBUG|Conversation__c: null
16:51:41:003 USER_DEBUG [40]|DEBUG|Group Name: null
16:51:41:003 USER_DEBUG [41]|DEBUG|Case: null
16:51:41:003 USER_DEBUG [42]|DEBUG|Opportunity: null
16:51:41:003 USER_DEBUG [43]|DEBUG|FirstName: null
16:51:41:003 USER_DEBUG [37]|DEBUG|Conversation: p7g180219__Conversation__c:{Group_Name__c=Tim Barr, FirstName__c=Tim}
You can see in the first line of the User_Debug, the values get passed into the method (without namespace, as expected). But then, I can't access them -- they're all null. Then, just for kicks, to make sure the initial values haven't been wiped, I issued the a repeat of the first System.debug -- and it provides all the values, as expected.
I know I must be doing something stupid here. Can anybody spot it?