+ Start a Discussion
jaysunjaysun 

getting record index / number from SOQL recordset

Is it possible to get record index using SOQL query?

i.e.

record 1 - 1

record2- 2

record -n

I want to render the record number in pageblock table or data table.

is there a way to display record index using Apex or visualforce contorls?

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_

The quickest way I can think is to basically build a wrapper class that has your sObject and also an index.  Then loop through your query and add them to the object numbering them.  Maybe someone else out there has a better way.

All Answers

Damien_Damien_

The quickest way I can think is to basically build a wrapper class that has your sObject and also an index.  Then loop through your query and add them to the object numbering them.  Maybe someone else out there has a better way.

This was selected as the best answer
Shashikant SharmaShashikant Sharma

no you can not directly, but if you create a map like 

Map<Id, index>

 

where key is map and index is record index in the list provided by SOQL . For creating map you can iterate over list returned by soql.

jaysunjaysun

Thanks...that is another way to make it work.

I craeted a wrapper class and added a property.

Both ways are finde.

jaysunjaysun

Yes..it worked.

created wrapper and added index as porperty to wrapper class.