+ Start a Discussion
Devendra@SFDCDevendra@SFDC 

How to Identify First Element of list

 

Hi,

 

 

How to identify first element in list?

 

For e.g.

 

             

for(Schedule_Task__c st:lstScheduleTask)

         {

         

             if(lstScheduleTask==0) // Is there any way to find out this is first element.

             {

                // 

             }

             else

             {

                //

 

}

}

 

Thanks and Regards,

Devendra S

Best Answer chosen by Admin (Salesforce Developers) 
Richie DRichie D

Hi,

 

Schedule_Task__c tsk = lstScheduleTask[0];

 will get you the first item out of the list - no need to do a for{} loop. Then just do your comparison on this object.

R.

All Answers

Richie DRichie D

Hi,

 

Schedule_Task__c tsk = lstScheduleTask[0];

 will get you the first item out of the list - no need to do a for{} loop. Then just do your comparison on this object.

R.

This was selected as the best answer
pankaj.raijadepankaj.raijade

Richie is correct.

 

but before this line please check if list is not null and size is gretter than 0, else it will throw error "list index out of bound"

 

Regards,

Pankaj Raijade

Devendra@SFDCDevendra@SFDC

 

Thanks to both of you.

 

Cheers,

Devendra S