You need to sign in to do that
Don't have an account?
ekm
Flex Apex Query and Subquery
Hi,
I'm attempting to run a query and a subsequent subquery based off the original query and then display the results in a datagrid. I'm having difficulty with the subquery and would appreciate any help or guidance as to what I need to do. Below is the portion of code that I'm working with. As I said, the Role field from the 1st query populates fine, but how do I get the results from the 2nd query.
Thanks,
[Bindable]
public var ar2:ArrayCollection = new ArrayCollection();
[Bindable]
public var ar:ArrayCollection = new ArrayCollection();
private function queryAccountManagerEdit1():void
{
currentState="searchAccountManagerEdit";
var acc:SObject = new SObject('AccountContactRole');
apex.query("Select ContactId, Role From AccountContactRole where Role = 'Decision-maker'",
new AsyncResponder(function (qr:QueryResult):void
{
for (var j:int=0;j<qr.records.length;j++)
{
ar.addItem( { ContactId:qr.records[j].ContactId, Role:qr.records[j].Role } );
//ar.addItem( { Role:qr.records[j].Role } );
apex.query("Select Id, Name From Contact where Id = ContactId:qr.records[j].ContactId",
new AsyncResponder(function (qr2:QueryResult):void
{
for (var k:int=0;k<qr2.records.length;k++)
{
ar2.addItem( {Name:qr2.records[k].Name});
}
//dgSearchAccountManagerEdit.columns = [ new DataGridColumn('Name'), new DataGridColumn('Role') ];
//dgSearchAccountManagerEdit.dataProvider = ar2;
}
)
)
}
// create the columns and specify the order
dgSearchAccountManagerEdit.columns = [ new DataGridColumn('Name'), new DataGridColumn('Role') ];
dgSearchAccountManagerEdit.dataProvider = ar; //assign the array as the data provider
}
) // closes new AsyncResponder(function (qr:QueryResult):void
); //closes 1st apex query
}
I'm attempting to run a query and a subsequent subquery based off the original query and then display the results in a datagrid. I'm having difficulty with the subquery and would appreciate any help or guidance as to what I need to do. Below is the portion of code that I'm working with. As I said, the Role field from the 1st query populates fine, but how do I get the results from the 2nd query.
Thanks,
[Bindable]
public var ar2:ArrayCollection = new ArrayCollection();
[Bindable]
public var ar:ArrayCollection = new ArrayCollection();
private function queryAccountManagerEdit1():void
{
currentState="searchAccountManagerEdit";
var acc:SObject = new SObject('AccountContactRole');
apex.query("Select ContactId, Role From AccountContactRole where Role = 'Decision-maker'",
new AsyncResponder(function (qr:QueryResult):void
{
for (var j:int=0;j<qr.records.length;j++)
{
ar.addItem( { ContactId:qr.records[j].ContactId, Role:qr.records[j].Role } );
//ar.addItem( { Role:qr.records[j].Role } );
apex.query("Select Id, Name From Contact where Id = ContactId:qr.records[j].ContactId",
new AsyncResponder(function (qr2:QueryResult):void
{
for (var k:int=0;k<qr2.records.length;k++)
{
ar2.addItem( {Name:qr2.records[k].Name});
}
//dgSearchAccountManagerEdit.columns = [ new DataGridColumn('Name'), new DataGridColumn('Role') ];
//dgSearchAccountManagerEdit.dataProvider = ar2;
}
)
)
}
// create the columns and specify the order
dgSearchAccountManagerEdit.columns = [ new DataGridColumn('Name'), new DataGridColumn('Role') ];
dgSearchAccountManagerEdit.dataProvider = ar; //assign the array as the data provider
}
) // closes new AsyncResponder(function (qr:QueryResult):void
); //closes 1st apex query
}
Select a.Id,a.Role,a.Contact.Id,a.Contact.Name from AccountContactRole a
For anyone interested, here's the related code:
[Bindable]
public var ar:ArrayCollection = new ArrayCollection();
private function queryAccountManagerEdit1():void
{
currentState="searchAccountManagerEdit";
var acc:SObject = new SObject('AccountContactRole');
//apex.query("Select ContactId, Role From AccountContactRole where Role = like '%" + txtAccountManagerEdit.text + "%'",
apex.query("Select a.Id, a.Role, a.Contact.Id, a.Contact.Name from AccountContactRole a where a.Role = 'Decision-maker'",
new AsyncResponder(function (qr:QueryResult):void
{
for (var j:int=0;j<qr.records.length;j++)
{
ar.addItem( { Role:qr.records[j].Role, Name:qr.records[j].Contact.Name } );
//ar.addItem( { Role:qr.records[j].Role } );
}
// create the columns and specify the order
dgSearchAccountManagerEdit.columns = [ new DataGridColumn('Name'), new DataGridColumn('Role') ];
dgSearchAccountManagerEdit.dataProvider = ar; //assign the array as the data provider
}
) // closes new AsyncResponder(function (qr:QueryResult):void
); //closes 1st apex query
}
Select a.Id, a.Role, a.Contact.Id, a.Contact.Name from AccountContactRole a where a.Role = 'Decision-maker'
But the following does not work (even in the Apex explorer).
Select a.Account.Id, a.Account.AccountNumber, a.Account.Name, a.AccountId, a.ActivityDate, a.ActivityDateTime, a.Type from Event a
Anyone have any thoughts? And back to my original question, would I have to subquery the accounts table to get the account info for each event?