You need to sign in to do that
Don't have an account?
Chris Sanchez 5
SOQL Relationship in Javascript
Hello, I have the following javascript in a button on the opportunity window which I believe works as the alert does display correctly. I havent been able to confirm if the child query portion is working correctly. How can I alert the select part of the child query? For example something like, var groupName = records[0].Groups__r.Name, then I would like to alert groupName. I appreciate your help.
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var groupID = sforce.connection.query("select Name, Id,(Select ID, Name, Head_Count__c FROM Groups__r) FROM Opportunity Limit 1" );
var records = groupID.getArray("records");
var Idee = records[0].Id;
var nam = records[0].Name;
alert(Idee + ' ' + nam);
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var groupID = sforce.connection.query("select Name, Id,(Select ID, Name, Head_Count__c FROM Groups__r) FROM Opportunity Limit 1" );
var records = groupID.getArray("records");
var Idee = records[0].Id;
var nam = records[0].Name;
alert(Idee + ' ' + nam);
There are 3 group records related to my test opportunity. When I run my query all 3 groups are placed in the the first result returned, in the 0 position in the array. How can I rewrite the query so I get a seperate result for each group? For example, records[2].Name would actually return a value?