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
AndegosuAndegosu 

Best way to assign list from SOQL query result

I always come across two ways of assigning results from a SOQL query to a list and I just wondered if there is any difference between the two:
1. List<Account> exampleOne = [SELECT Id, Name FROM Account WHERE Name = 'John'];
2. List<Account> exampleTwo = List<Account>([SELECT Id, Name FROM Account WHERE Name = 'John']);
Best Answer chosen by Andegosu
Steven NsubugaSteven Nsubuga
Line 2 should be List<Account> exampleTwo = new List<Account>([SELECT Id, Name FROM Account WHERE Name = 'John']);

And, there is no difference between tge 2, use whichever you prefer.

All Answers

Steven NsubugaSteven Nsubuga
Line 2 should be List<Account> exampleTwo = new List<Account>([SELECT Id, Name FROM Account WHERE Name = 'John']);

And, there is no difference between tge 2, use whichever you prefer.
This was selected as the best answer
AndegosuAndegosu
I knew I would make a mistake writing code in plain text... Thanks!