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
mibropmibrop 

Attachment Recordset Problem in Flex (possibly not Flex related)

I extended the Flex sample app to populate a DataGrid with the Id and Name of Attachment objects from Salesforce.

However, I've encountered an issue where if I attempt to put the Id and Name in the same row in the DataGrid, it fails. However, if the Id and Name are on separate rows (two separate ArrayCollection.addItem statements) then it works. This happens with any query where I bring back multiple fields and attempt to show them in the same row in the DataGrid.

Here's a snippet of the relevant code that does not work:
  private function render():void{

apex.query("Select Id, Name FROM Attachment",
new AsyncResponder(
function(qr:QueryResult):void{
var ar:ArrayCollection = new ArrayCollection();

for (var j:int=0;j<qr.records.length;j++) {
ar.addItem( {Id:qr.records[j].Id}, {Filename:qr.records[j].Name} );
}

bg.columns = [new DataGridColumn('Id'), new DataGridColumn('Filename')];
bg.dataProvider = ar;

},
function (fault:Object):void{

}
));
}

However, the following code does work:
  private function render():void{

apex.query("Select Id, Name FROM Attachment",
new AsyncResponder(
function(qr:QueryResult):void{
var ar:ArrayCollection = new ArrayCollection();

for (var j:int=0;j<qr.records.length;j++) {
ar.addItem( {Id:qr.records[j].Id} );
ar.addItem( {Filename:qr.records[j].Name} );
}

bg.columns = [new DataGridColumn('Id'), new DataGridColumn('Filename')];
bg.dataProvider = ar;

},
function (fault:Object):void{

}
));
}


 

dbelwooddbelwood
mibrop,

Try replacing:
   
ar.addItem( {Id:qr.records[j].Id}, {Filename:qr.records[j].Name} );

with:
ar.addItem( {Id:qr.records[j].Id, Filename:qr.records[j].Name} );

The addItem method expects one associative array.

mibropmibrop
That did it! Thanks so much for your help.

Mike
Seattle