You need to sign in to do that
Don't have an account?
Davidvzla
Really dumb question about SOQL
I don't know what is the number inside the square brackets in SOQL used for? for instance, number 0 (zero) inside square brackets. Thanks for your help.
1Account[] acctsWithContacts = [SELECT Name, (SELECT FirstName,LastName FROM Contacts)
2 FROM Account
3 WHERE Name = 'SFDC Computing'];
4// Get child records
5Contact[] cts = acctsWithContacts[0].Contacts;
6System.debug('Name of first associated contact: '
7 + cts[0].FirstName + ', ' + cts[0].LastName)
1Account[] acctsWithContacts = [SELECT Name, (SELECT FirstName,LastName FROM Contacts)
2 FROM Account
3 WHERE Name = 'SFDC Computing'];
4// Get child records
5Contact[] cts = acctsWithContacts[0].Contacts;
6System.debug('Name of first associated contact: '
7 + cts[0].FirstName + ', ' + cts[0].LastName)
For example, in line 5 you have acctsWithContacts[0].Contacts.
This means you are getting the first account in the acctsWithContacts array of accounts.
acctsWithContacts[1] would get the second account, acctsWithContacts[2] gets you the third, etc.
Hope that explains it! Please mark as best answer if this helped!
All Answers
For example, in line 5 you have acctsWithContacts[0].Contacts.
This means you are getting the first account in the acctsWithContacts array of accounts.
acctsWithContacts[1] would get the second account, acctsWithContacts[2] gets you the third, etc.
Hope that explains it! Please mark as best answer if this helped!