Skip to main content
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']);
2 answers
  1. May 31, 2018, 7:25 PM
    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.
0/9000