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
jf317820jf317820 

flex toolkit bug or my stupidity?

in the flex toolkit, is there a way to catch the "Cannot access a property or method of a null object reference." when a query returns a null value?  my problem is I have a query with a nested query and whenever the nested query returns zero records, the object is returned as "null" and the null reference message is thrown, even thwarting my best attempts at catching it.

thanks in advance
Ron HessRon Hess
which flex toolkit version are you using?
can you post an example of your query processing loops.

normaly you would test the nested query object against null before accessing the ".records.length"

i don't think it's a bug, and i'm sure you can catch the null access before it happens, are you using Flex Builder?
it has a great debugger allowing you to step thru the code, even look at vars.


jf317820jf317820
i'm using the 3.7 version (i believe it's the latest).  here's my code:

Code:
apex.query("Select Id, Name, StageName, (Select Status, TargetObjectId, CreatedDate From ProcessInstances where Status = 'Pending' order by CreatedDate DESC LIMIT 1) " + 
 "from Opportunity where StageName = 'Prospecting'", 
  new AsyncResponder(function (qr:QueryResult):void
             {
                for (var j:int=0;j<qr.records.length;j++) { 
                 if (qr.records[j].ProcessInstances != null){
  ar.addItem(  { Id:qr.records[j].Id, "Deal Name":qr.records[j].Name } ); 
        }               
       }
       dg.columns = [ new DataGridColumn('Deal Name') ]
       dg.dataProvider = ar; // assign the array as the data provider
     } )
  );
if (qr.done == true){
loadData2();
}
 }

 

Message Edited by jf317820 on 08-03-2007 01:27 PM

DevAngelDevAngel
Always check the size property on a query Result.

if (qr.size > 0) {
    //do your query processing here.
}


Cheers
jf317820jf317820
the qr.size is coming back as 13 or whatever it is, the problem is when one of the records returned does not have a ProcessInstances record associated (inner query).  i try catching it with

Code:
if (qr.records[j].ProcessInstances != null){

}

 but the code above is what's producing the error.  shouldn't i be able to make the above if statement?

DevAngelDevAngel
Ok, I see.

Try qr.records[i].hasOwnProperty("ProcessInstances");

This function is for dynamic objects and will indicate if that field exists on the record.



Cheers.
jf317820jf317820
hmm...firstly, that function doesn't seem to be filtering out records with a null ProcessInstances record. secondly, it's still throwing a null reference error.  perhaps i'm using it incorrectly?  here's my code:

Code:
for (var j:int=0;j<qr.records.length;j++) { 
   if (qr.records[j].hasOwnProperty("ProcessInstances")){
 ar.addItem(  { "Deal Name":qr.records[j].Name } ); 
        }               
       }