The process of dataset is kicked off when a user creates a dataset custom object record. We will use trigger to call the scheduled job to the created dataset. To train the model, we will use the chaining series of scheduled Apex jobs. The following table lists the apex scheduled jobs and the working code link to the relevant git repository:
The trigger code that automatically starts a scheduler is as follows:
trigger TriggerOnEinsteinVisionDataset on
Einstein_Vision_Dataset__c (after insert) {
//Not bulkified purposefully so that we only
trigger for individual records inserted via UI
//Use extreme caution if you plan to further bulkify this method
if(trigger.new[0].Status__c == 'STARTED'){
//Schedule the process of creating and training dataset
System.schedule('DatasetCreateJob', '0 '+
DateTime.now().addMinutes(2).minute()+' */1 ? * *', new
EinsteinVisionCreateDatasetScheduler(trigger.new[0].Id));
}
}
Note that trigger is not bulkified, and assuming that the user adds the records one by one, there is a single admin with a privilege to create the dataset record. You can use the permission sets to control the application access, tab access, and objects' CRUD (Create, Read, Update, and Delete) access.
The following flowchart shows the sequence of jobs:
As an administrator, once a dataset record is created, it will take some time to get modelId and the training status. Currently, jobs are scheduled to run every two minutes. The following screenshot shows the administrator screen once a model is completely trained and ready to use the model to ask for predictions:
Note that ModelId is shown in the preceding screenshot. As an administrator, you will need the ModelId for the smart image recognition lightning component that we are building in the next section.