function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shayne0Shayne0 

sforce.QueryResultIterator for nested queries

I'm creating a customized button. The Query is a nested one as follows:

 

var primaryContact = sforce.connection.query("SELECT Account.Name, (SELECT Contact.FirstName FROM OpportunityContactRoles) FROM Opportunity WHERE Id='{!Opportunity.Id}'");

 

The query is a success. But I'm not able to access Contact.FirstName using sforce.QueryResultIterator. The error read: "Can not read property FirstName of undefined". My code is:

 

if ( primaryContact .size > 0) {
     var it = new sforce.QueryResultIterator(primaryContact );
     while (it.hasNext()) {
               var query = it.next();
               var firstName = query.OpportunityContactRoles.Contact.FirstName;
     }
}

 

Please let me know how to access FirstName using the sforce.QueryResultIterator.

Lalit_RautelaLalit_Rautela
You can try this .........it will work

var oit = new sforce.QueryResultIterator(primaryContact);
while(oit.hasNext()){
var oppor = oit.next();
var OppConRoleFirstName = [];
if(oppor.OpportunityContactRoles){
var oppRole = new sforce.QueryResultIterator(oppor.OpportunityContactRoles);
while(oppRole.hasNext()) {
        var OppCOntRol = oppRole.next();
        OppConRoleFirstName.push(OppCOntRol.Contact.FirstName);
      }
}
}