+ Start a Discussion
TCAdminTCAdmin 

Variable matching

I've got this code and I'm trying to do a query of the system using a JS variable as the matching value.  The "id" field is the 18 digit Account Id value.  I'm trying to pull all Opportunities that are associated with the Account with this id.  When I alert the oppValues I get the following values even though I know there are Opportunities associated with the Account Id I'm using.  Can someone give me the syntax that would do what I want?

Query Result [1]:
size: 0
queryLocator: null
done: true
QueryResult [1] ***********************************

Code:
var account = accValues.records[cnt];
var id = account.get("Id");
var oppValues = sforceClient.query("SELECT AccountId, Amount FROM Opportunity WHERE AccountId = 'id' ");

 Thanks in advance for any help.

DevAngelDevAngel
I would try
var account = accValues.getArray("records")[cnt];

You might not have an array in your outer loop.
zakzak
var id = account.get("Id");
var oppValues = sforceClient.query("SELECT AccountId, Amount FROM Opportunity WHERE AccountId = 'id' "); 
your query is for the for the id with a literal vaule of 'id' of which there never will be any, you need
var id = account.get("Id");
var oppValues = sforceClient.query("SELECT AccountId, Amount FROM Opportunity WHERE AccountId = '" + id + "'"); 

Message Edited by zak on 02-26-2007 09:19 AM

TCAdminTCAdmin
zak,

Thank you, that works perfect.  I knew it had to be just an error with the quotes but I couldn't figure it out.