Using Apex to generate synthetic Race Data

Just like me, I doubt if you have a real Formula 1 race team or car to provide raw data input. We will be using an Apex code to generate synthetic test data in this section, though in reality, race data may be inserted through a CSV file import or through an IoT integration with the driver's car. Ingesting a live stream of race data via the Salesforce APIs using Platform Events is something we will be exploring later in this chapter in the Asynchronous processing with Platform Events section.

For now, the following Apex code will generate 10,000 rows, which is about enough to explore the SOQL profiler, which makes different choices dependent on row count. Due to the volumes of data being created, you must run each of the following Apex statements one by one to stay within the governors. Use the sfdx force:apex:execute command (without parameters) and paste in the following one at a time. Then, as indicated by the onscreen instructions, press the appropriate key to execute the code.

  1. Run TestData.resetTestSeason();.
  2. Run TestData.purgeVolumeData(false);.
  3. Run TestData.purgeVolumeData(true);.
  4. Run TestData.createVolumeData('Spain', 52, 4);.
Step 1 of the preceding steps will run a script that will clear down all other data from other FormulaForce objects in order to set up test Season, Race, and Driver data for the rest of the chapter. You can repeat step 4 to generate a further 10,000 Race Data records for additional races—something we will do later in this chapter. This step might take a few seconds to complete.

Once the script has been executed, go to the Race Data tab and review the data. The values shown in the Value column are random values, so your results will differ:

You should also see the following row count if you review the Storage Usage page:

Now that we have loaded some sample data through the preceding scripts, in the next section, we will review the effects of different queries on that data with respect to the presences of indexes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.142