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
AnicheAniche 

Accessing Arrays

I have created an array which stores 1 row of data from the SOQL that i executed. The code is Lead[] lead1 = [Select l.AnnualRevenue, l.Name from Lead l where l.OwnerId = 'whatever' and l.AnnualRevenue > 540000000]; system.debug(Second field is '+lead1[1]); This gives and error saying "List index out of bounds" Since i have 2 fields that i have pulled in the query i have put 1 in the index. Can somebody help me to understand my problem, If someone has array examples storing single resultset and multi result set the it would be helpful. Thanks
AnicheAniche
Oops.... I learnt this - Since the resultset has only 1 record and is giving Out of bounds error so basically what my array[1] is trying to do is access second record in the array. Now my question is how to access individual columns in the array ? Hopefully i get this one too but will surely appreciate any replies.. Thanks.
SuperfellSuperfell
lead1[0].name
AnicheAniche
Thanks.. That was easy.. Appreciate that