Does anyone know how to or if it is possible to pull data from the related list of an object using Remote Objects? I can query the object's related list without error however it is undefined and I cannot seem to find references on this in the documentation.
1 Answer
Bit late to the party, but as far as I can tell (and from experimenting) you can only query fields on the object itself. This means to get related information you then have to make subsequent calls to those objects filtering by the lookup Id.
This is a snippet of code I've been using (note I'm using UnderscoreJS to help out a little).
// Client id is my JS name for the ContactId field
var clientIds = _.uniq(events.map(function(e) { return e._Client; }));
clientIds = _.reject(clientIds, function(c) { return !c; });
if(clientIds.length === 0)
{
success(events);
return;
}
// this method perforces a remote object query on contact
self.loadClientsById(clientIds, function(clients)
{
var mapped = events.map(function(e)
{
for(var i = 0; i < clients.length; i++)
if(clients[i].Id === e._Client)
{
e._Client = clients[i];
break;
}
return e;
});
// now mapped is an array of events, where each has a contact object
// contained within it under the _Client property;
doSomeCallback(mapped);
});
-
1Hi Lacey, that is what I have found also... it would be a nice feature to be able to access related objects without another call Sep 3, 2015 at 16:16
-
Absolutely. Also, I have just discovered that remote objects can be very slow when searching across large data sets. I'm not sure why but it was timing out at around 30 seconds when a similar call via the REST API took 2-3 seconds. \– Matt Lacey ♦Sep 4, 2015 at 1:47