Apex 中的 SOQL 查詢

要在 Apex 中執行查詢,請使用方括號括起查詢。結果可以分配給列表或單個物件。

List<Account> allAccounts = [SELECT Id, Name FROM Account];
Account oldestAccount = [SELECT Id, Name FROM Account ORDER BY CreatedDate LIMIT 1];