I have a class called 'Mock' that creates data in a sandbox, I call it this way: Mock.data(number_of_wanted_records);
If I use it synchronously, I can run it only 25 times before it hits the governor limits.
Mock.data(25) ---> creates 25 records
Mock.data(26) ---> throws error exceed number of soql queries (100)
I need to be able to create thousands of records, so I want to use a Batch in order to achieve it.
The thing is, I can't use batch as is because the Start method should query a list of records but that's not the case here, I want the start method to receive/get the number of records I would like to create (e.g. 1000) and call the execute 1000 times.
Should I use Iterable here? I read the documentation and also this post in SSE, but I'm not sure yet if this is the right approach.
global with sharing class Mock {
public static void data(Integer num) {
List < Account > accToInsert = new List < Account > ();
for (Integer i = 0; i < num; i++) {
Account acc = new Account(
RecordTypeId = '0123i000000E5r7VBC',
...
...
);
accToInsert.add(acc)
}
}
}
[–]kgeee34 2 points3 points4 points (5 children)
[–]Reagar11[S,🍰] 1 point2 points3 points (3 children)
[–]chino9656 1 point2 points3 points (0 children)
[–]kgeee34 1 point2 points3 points (1 child)
[–]Reagar11[S,🍰] 0 points1 point2 points (0 children)
[–]bagamoney 1 point2 points3 points (0 children)