A developer has a requirement to query three fields (Id, Name, Type) from an Account and First and Last names for all Contacts associated with the Account. Which option is the preferred optimized method to achieve this for the Account named ‘Ozone Electronics’?
A. Account a = [SELECT ID, Name, Type FROM Account WHERE name=‘Ozone Electronics’]; list lContacts = [SELECT firstname, lastname FROM Contact WHERE accounted=:a.ID];
B. Account a = [SELECT ID, Name, Type, (SELECT FirstName, LastName FROM Contacts) FROM Account WHERE name=‘Ozone Electronics’ LIMIT 1];
C. list lContacts = new list();
for (Contact c :[SELECT firstname, lastname, Account.Name, Account.ID, Account.Type FROM Contact WHERE Account.Name=‘ozone electronics’]) ( lContacts.add(c); )
D. list lAccounts = [SELECT ID, Name, Type FROM Account JOIN (SELECT ID, firstname, lastname FROM Contact WHERE contact.account.name = ‘ozone electronics’)];
Suggest answer: A
Reference:
No comments:
Please share to make the community better.