The SELECT keyword is used at the beginning of a SOQL query to define which fields you want to retrieve from an sObject. The basic syntax for a SELECT statement is:
SELECT AccountNumber FROM Account
This query retrieves the Account Number from every Account record in Salesforce. When writing a SELECT statement, notice that we're referencing the field's API Name, not the label.
When we want to retrieve more than one field, we separate them with a , comma. Let's also retrieve the Accounts' Name and Website:
SELECT Name, AccountNumber, Website FROM Account
| Name | AccountNumber | Website |
|---|---|---|
| Edge Communications | CD451796 | http://edgecomm.com |
| Burlington Textiles Corp of America | CD656092 | www.burlington.com |
| Pyramid Construction Inc. | CC213425 | www.pyramid.com |
| … | … | … |
Similarly, we can retrieve the Name, Birthday, and Email fields from Contact:
SELECT Name, Email, Birthdate FROM Contact
| Name | Birthdate | |
|---|---|---|
| Rose Gonzalez | rose@edge.com | 23616 |
| Sean Forbes | sean@edge.com | 15852 |
| Jack Rogers | jrogers@burlington.com | |
| … | … | … |
Or Opportunity, with its custom OrderNumber__c field:
SELECT Name, StageName, ExpectedRevenue, OrderNumber__c FROM Opportunity
| Name | StageName | ExpectedRevenue | OrderNumber__c |
|---|---|---|---|
| Dickenson Mobile Generators | Qualification | 1500 | |
| United Oil Office Portable Generators | Negotiation/Review | 112500 | |
| Express Logistics Standby Generator | Closed Won | 220000 | 653276 |
| … | … | … | … |