[4.2] - rbf_selectQuery2 returns only one record for multipl

Posted by IramK on 06-Jul-2016 03:47


I have a select Query for an account that has multiple contacts (1:M relationship) and I would like to get all the related contacts from the contact field in account but my select query is just returning one of the contact records instead of all. Any reasons why?

rbf_selectQuery2("select contacts FROM account WHERE id=232885", 0, 1000, function returnCallback(values) {
console.log(values[0][0]); // returns only one contact


All Replies

Posted by Shiva Duriseati on 07-Jul-2016 05:03

Hi Iram,

Can you please cross check this?


You are printing only one record from the resulting array.



Posted by IramK on 07-Jul-2016 05:46

Hello [mention:efd18cd3210243c3a2645cbe9409d974:e9ed411860ed4f2ba0265705b8793d05] ,

I originally had this selectQuery basically which is why that console.log was left there.

rbf_selectQuery2("select contacts, id FROM account WHERE id=232885", 0, 1000, function returnCallback(values) {

console.log(values[0][0]); // returns only one contact


So in the above selectQuery, how can I get all the contacts that are related to it with that contacts lookup field?


Posted by Shiva Duriseati on 07-Jul-2016 06:11

Hi Iram,

I tried on contact object by passing ID of the account to the query and I am able to get all the contacts associated with the Account object.

rbf_selectQuery2("SELECT name FROM Contact_1 WHERE R39815=39826",0,1000, function callback(arr){

   for(var i=0;i<arr.length;i++){






Posted by IramK on 13-Jul-2016 03:38

Hi [mention:efd18cd3210243c3a2645cbe9409d974:e9ed411860ed4f2ba0265705b8793d05] ,

That would work but I am trying to get the account information and the related contacts in one selectQuery rather than making two API calls. Is that possible?


Posted by IramK on 15-Jul-2016 06:05

Also I would like to make a comparison in the WHERE clause with the account fields and not from the contact fields. Is there a possibility of checking that in the selectQuery you mentioned?


Posted by Santosh Patel on 17-Jul-2016 00:40

Due to the nature of implementation of selectQuery and related apis it is not possible to retrieve a many sided relationship using a single query. You will have to use getRelatedIds to retrieve the list of contacts for an account.

If there is still an optimization on number of API calls you are looking for, I'd suggest adding limited account fields as related fields on the contact object and running the query as Shiva suggested.

Posted by IramK on 17-Jul-2016 06:45

Hello [mention:7e24e60fbecc4ff8baf4669a65bae0a0:e9ed411860ed4f2ba0265705b8793d05] ,

Agreed but provide me with a resolution for this relating to the related fields on the contact object suggestion:

So basically I have fields in Account that are picklists and if I use a selectQuery in Contact by using related fields for those picklist fields in Accounts, it only returns the ID's and then I have to do another rbf_getCodeById() API call to retrieve those codes. I can't use the [tag:code] or [tag:value] for those related fields in Contact. Could you suggest me a way to do this by using only one API call.



Posted by Santosh Patel on 18-Jul-2016 04:03

You could cache your picklist data on client-side in browser session storage and resolve picklist codes using that.

if (!sessionStorage.getItem('DPickListField')) {
	rbf_getPicklist('RBObjWithAllFields', 'DPickListField', -1, function(data) {
		if (data && data.length>0) {
			var pickListFieldData = {};
			for (var i=0; i<data.length; i++) {
				pickListFieldData[data[i].id] = data[i].name;
			sessionStorage.setItem('DPickListField', JSON.stringify(pickListFieldData));

function resolveDPickListField(id) {
	var data = JSON.parse(sessionStorage.getItem('DPickListField'));
	return data[id];

DPickListField - integration name of your picklist field
RBObjWithAllFields - integration name of your object

Use resolveDPickListField method to resolve the pick item names without having to make an API call. Storing of data would be a single call per user session. The only caveat is around change to the picklist field definition. You can handle that in resolve method. When a resolution fails make the getPicklist call again to fetch fresh data once and if it still does not resolve then it is an invalid id.

Posted by IramK on 09-Aug-2016 04:19

Thanks [mention:7e24e60fbecc4ff8baf4669a65bae0a0:e9ed411860ed4f2ba0265705b8793d05] ,

This sounds like a good option to me. This is a browser session storage option. Is there a way where I could use the rollbase session to achieve the same? :)


Posted by Santosh Patel on 09-Aug-2016 04:49

Anything not browser storage will involve calls to/from the server, which is what you are trying to avoid.

This thread is closed