1

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?

1
  • P.S. If you were using Salesforce DX, you could create a namespaced org to develop in, and then you wouldn't have to worry about fiddling with namespace vs non-namespace orgs.
    – sfdcfox
    Commented Feb 22, 2018 at 13:49

1 Answer 1

1

I think this is just one of the bugs you will need salesforce support .

What always have worked is to stringify the JSON and send as String and then parse in the apex .

@AuraEnabled
public static Id saveConversation(String Conversation)
{    
    Conversation__c Conversation = (Conversation__c)JSON.deserialize(Conversation,Conversation__c.class)
    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;
}
2
  • Thanks Mohith. I used your wrapper approach for the SOQL query part, though it's very frustrating that you can't include variable names in the wrapper class that include __c. That meant that I still had to do some editing on my components. Commented Feb 22, 2018 at 1:31
  • I think this is one of the things with just passing strings back and forth is faster as well . Commented Feb 22, 2018 at 1:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .