Create SOQL to Return Data to Apex
Follow Along with Trail Together
Want to follow along with an expert as you work through this step? Take a look at this video, part of the Trail Together series.
(This clip starts at the 24:15 minute mark, in case you want to rewind and watch the beginning of the step again.)
Create a Query
Create a SOQL query to retrieve the Recruiting Account record that you created.
- In the Developer Console, click File | Open Resource.
- Select Account.obj and then click Open.
- Select Id and Name. Use CTRL (in Windows) or CMD (on a Mac) to select multiple fields.
- Click Query.
- If the Query Editor displays instructions for building a query, click Query again.
- At the end of the query, type
WHERE Name = 'Recruiting'
. - Verify that your SOQL query reads:
SELECT Id, Name FROM Account WHERE Name = 'Recruiting'
- Click Execute to execute the query and display the results.
To associate the newly created Contact with the Recruiting Account, add the SOQL query to the createContact method.
- In the CreateContactFromCan class, replace the existing code with this code:
- Save the CreateContactFromCan class.