You need to sign in to do that
Don't have an account?
Brian Koblenz
query return not providing q.records.length
I feel a bit stupid. I have a pretty straightforward javascript custom button where I am trying to do a query and then iterate over the resulting set of objects.
My broken code is:
query_str = 'Select Id, ' +
'RecordType.Name, QB_Propagated__c ' +
'FROM Opportunity WHERE ' +
'QB_Propagated__c=false AND ' +
'RecordType.Name=\'Donation\' AND ' +
'Id IN (\'' + idArray.toString().replace(/,/g, "','") + '\')';
alert(query_str);
ores = sforce.connection.query(query_str);
alert(ores);
alert('len: ' + ores.records.length);
The ores.records is defined and appears to be a list of entities that I want to iterate over (an alert(ores.records) gives me an object that starts {type:.....,} ), but my alert referencing the length of ores.records is undefined.
If I use the same query but do NOT include the AND ID IN ('sfid1','sfid2') in the query then the ores structure looks the same (to my eye!) but the code does work and I can refer to ores.records.length and get something meaningful.
In the "failing" version there is only one record that satisfies the condition. If I extend my test so that two records satisfy my condition then I get the expected behavior.
Is it possible that I need two versions of code to deal with <=1 record returned from the query and >1 record? I was hoping to just iterate over the length of the list.
-brian
My broken code is:
query_str = 'Select Id, ' +
'RecordType.Name, QB_Propagated__c ' +
'FROM Opportunity WHERE ' +
'QB_Propagated__c=false AND ' +
'RecordType.Name=\'Donation\' AND ' +
'Id IN (\'' + idArray.toString().replace(/,/g, "','") + '\')';
alert(query_str);
ores = sforce.connection.query(query_str);
alert(ores);
alert('len: ' + ores.records.length);
The ores.records is defined and appears to be a list of entities that I want to iterate over (an alert(ores.records) gives me an object that starts {type:.....,} ), but my alert referencing the length of ores.records is undefined.
If I use the same query but do NOT include the AND ID IN ('sfid1','sfid2') in the query then the ores structure looks the same (to my eye!) but the code does work and I can refer to ores.records.length and get something meaningful.
In the "failing" version there is only one record that satisfies the condition. If I extend my test so that two records satisfy my condition then I get the expected behavior.
Is it possible that I need two versions of code to deal with <=1 record returned from the query and >1 record? I was hoping to just iterate over the length of the list.
-brian
var records = result.getArray("records");
and then use records.length instead of ores.records.length
All Answers
var records = result.getArray("records");
and then use records.length instead of ores.records.length