Recipes Without File #
A new bread can be created and started automatically with the following Apex or the equivalent in Flow.
insert new slicedbread__Bread__c(
Name = '{!bread_number} | My Bread',
slicedbread__Status__c = 'Start Slicing',
slicedbread__Recipe_Name__c = 'My_Recipe'
);
Recipes With File #
For file based slicers, automation works slightly different. First create the bread. The default status is New.
slicedbread__Bread__c bread = slicedbread__Bread__c(
Name = '{!bread_number} | My Bread',
slicedbread__Recipe_Name__c = 'My_Recipe'
);
insert bread;
Then attach a file to the bread. Please refer to Salesforce documentation on how to automate this. Afterwards you can start slicing by updating the status.
bread.slicedbread__Status__c = 'Start Slicing';
update bread;
Bread Virtual Fields #
If the recipe contains Bread virtual fields, then you can initialize these as well. The Virtual Fields field requires JSON format.
insert new sicedbread__Bread__c(
Name = '{!bread_number} | My Bread',
slicedbread__Status__c = 'Start Slicing',
slicedbread__Recipe_Name__c = 'My_Recipe',
slicedbread__Virtual_Fields__c = '{"Bread.Campaign__vf": "7017a0000015vxnAAA"}'
);
Sliced Bread does not yet support Bread custom fields, which would make automation easier, definitely with Flow. Supporting Bread custom fields is on the roadmap (forward looking statement).
Scheduling Sliced Bread recipes #
A recipe can be scheduled by running the following command in Anonymous Apex:
slicedbread.Api.scheduleRecipe('CRON EXPRESSION', 'RECIPE API NAME', 'VIRTUAL FIELDS');
Example of scheduling a recipe to run every 2 hours, starting next midnight:
slicedbread.Api.scheduleRecipe('0 0 0/2 1/1 * ? *', 'Generate_One_Account');
Example of scheduling a recipe including initialized virtual fields:
slicedbread.Api.scheduleRecipe('0 0 0/2 1/1 * ? *', 'Generate_Contacts', new Map<String, Object>{'Bread.Number_Of_Slices__vf' => 10});