Setting up test data
When you declare a test class with test methods, you need to assume that you have an empty database. So, we need to create some test data to perform our tests.
You can create test data in different ways. If you are already an advanced developer, you'll work with a test data factory, where you will be able to create predefined objects and records (each account record needs a name, so in the factory, you can define a name when you create a test account). A good example of a test data factory can be found here: https://medium.com/@medben/apex-test-data-factory-8ed14c2ca050.
In this section, I'll teach you the basics of creating Salesforce test data, but don't hesitate to use a factory.
Without a factory, you are able to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access