You need to sign in to do that
Don't have an account?
trish
undefined message when there is only 1 record in a custom object
Hello,
I am trying to retrieve the records from a custom object dynamically and display it in S-Control as a list. My code works as long as there are more than 1 record, the query works correctly. However, if there is only 1 record, then "for" loop is skipped in the following code snippet is skipped. Value "qr.records.length" is set to undefined. Am I doing something wrong here?
var qr = sforce.connection.query("SELECT ID, Contact__c from CCList__c");
for(i=0;i<qr.records.length;i++)
{
....... Logic for displaying the record.....
for(i=0;i<qr.records.length;i++)
{
....... Logic for displaying the record.....
}
You get a different structure in qr when there is only one record returned; not an array with just one entry, but the entry itself.
Throw a Try/Catch around the for loop, I suspect you're dying with an error to the effect that qr.records doesn't exist.
Use:
-Steve
Thank you werewolf and SteveBower. The queryResultIterator worked!!!