2

I have a @remoteaction method that is a query on contacts with a subquery on a custom object.

When I get the response in javascript I'm using JSON.stringify() to examine the response and I'm not getting the subquery results:

[Log] [{"Name":"test guy","RecordTypeId":"012G0000000zOTZIA2","CreatedDate":1402533032000,"Id":"003J000000woxFNIAY"},{"Name":"test guy2","RecordTypeId":"012G0000000zOTZIA2","CreatedDate":1402582703000,"Id":"003J000000wpMGFIA2"}] (cordova, line 5180)

Has anyone been able to successfully receive the response from a subquery through a @remoteaction?

2

Yes, sub-queries are returned normally. Here's a simple example:

Controller

public with sharing class remote {
    @RemoteAction public static Account getAccounts() {
        return [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Name = 'Test' LIMIT 1];
    }
}

Page

<apex:page controller="remote">
    <script>
    (function() {
        {!$RemoteAction.remote.getAccounts}(function(d,e) {
            var x = document.querySelector('#content'),
            t = document.createTextNode(JSON.stringify(d));
            x.appendChild(t);
        });
    }());
    </script>
    <div id="content"></div>
</apex:page>

Output in my org:

{"Name":"test","RecordTypeId":"012500000009cP9AAI","Contacts":[{"Name":"test","AccountId":"0015000000saUyLAAU","Id":"00350000022OKpIAAW"}],"Id":"0015000000saUyLAAU"}
  • yes, sorry I must have been staring at the screen too long, the records I was testing didn't have any sub records..duh – Phil B Jun 14 '14 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.