Salesforce Fact #6 | Id not needed
Considering the below query returns result, do you think is there any error:
Account a = [SELECT Name FROM Account LIMIT 1];
System.debug(a.Id);
You
might think that a.Id will generate an error as Id field is not fetched
in the SOQL query. But the thing is, ID field is implicitly returned in
case of SOQL query result. So the above query is interpreted as:
Account a = [SELECT Id, Name FROM Account LIMIT 1];
Hence, we need not specify Id field explicitly in the SOQL query unless we are doing some kind of existence check like:
List<Account> accList = [SELECT Id FROM Account WHERE Name=<inputname>];
Comments
Post a Comment