0

I am trying to create more than 50000 records with a press of a button inside salesforce for a full month. The records needs to be displayed with a timestamp of 5 minutes apart.

Something like this:

If i pick month June it has 31 days and in those 31 days i have 12 hours and every hour has 60 minutes and there are 12 records inside (5min each) So i need to create 12*12*30 = 4464 records just for one month and i will need to create for 12 months for full year which is around 53000 records.

Is there a simple way to create them with just a press of a button or something in a custom object tab where i select the month or something?

I need any idea possible out there. Need to know if this is even possible and if it is how to do it, best ways to do it,sample code etc...

So here is an update that i did.Decided to go just with apex and this is the code that i did so far:(I know it is horrible)

List<Courses__c> course =[select id from courses__c];
List<Available_Time__c> cList = new List<Available_Time__c>();
for(Courses__c i: course){
     for(Integer j=0;i<2;i++){
        Available_Time__c cust = new Available_Time__c();
        cust.Course__c = 'a0C0D000000Q7qbUAC';
    }
}
insert cList; 

What i am trying to achieve is get the courses available and add time for a specific month of june(31)2019 days to auto create 48 records per day per course starting from 6am to 6pm with a time to update every 5 minutes.

Any help is appreciated allot.

Thanks, Darko

8
  • where do you have these information? You could use Dataloader to load it if you have in a spreadsheet, for example. If you have in SFDC. Also, you could get it using Data Load and after load again. Will you need it only one time? Or will you need to run it again?
    – m Peixoto
    Dec 4, 2018 at 15:56
  • 1
    There's a variety of possible solutions, including those that don't even require pushing a button at all, but they all involve writing code. Visualforce, Lightning, Apex Scheduler are three different ways you could start the process, and you could use either Queueable or Batchable to generate the records. There's also a minor concern about why you need to create 106 MB of records every year, that's going to eat up a lot of your storage. This might even be an X-Y problem. What's your overall objective?
    – sfdcfox
    Dec 4, 2018 at 16:24
  • Sounds to me like this is an X-Y problem. What problem are to trying to solve where creating tens of thousands of records is the solution?
    – Derek F
    Dec 4, 2018 at 16:24
  • my objective is to create this timestamps so i can get free spots for available time periods for a person to spend on court. I need this so that i can show available options depending on certain rule criteria used to calculate the price for a specific user and specific product. It will be nice to auto generate them so i wont need to use data loader instead to select a year or month and auto create them all. Dec 4, 2018 at 16:34
  • also i want to test to see how long it will take for them to be created. Like sfdcfox mentioned how much data will it consume. Should i just use the developer console and try create like random 50k records just to see this if its possible and what is the best way to do so. Dec 4, 2018 at 16:36

1 Answer 1

0

Ok so this is what I did. I created an apex code that checks the courses and then add the records for 30 days for a full month of June 2019. Inside those days it adds 144 records with every record starting from 6 am to 6 pm (total 144 records).

I know that this code is total nonsense and this approach is not good to do. Better approach is to have a code-generated list of times on the UI Level instead of the database level. That is, a VF page that displays a list of times for you to pick, instead of picking it from a database list.

Below is the code.

List<Courses__c> course =[select id from courses__c];
for(Courses__c i: course){
    List<Available_Time__c> cList = new List<Available_Time__c>();
    //start date
    Date myDate = Date.newInstance(2019,6,1);
    Date finishDate = myDate.addDays(30); //or for any mounth use the line below.
   // Date finishDate = myDate.addMonths(1).addDays(-1);
    while(myDate<finishDate){
        //Start at 06:00
        DateTime dt = DateTime.newInstance(myDate, Time.newInstance(6,0,0,0));
        while (dt.hour() < 18) { //Until 18:00
            Available_Time__c cust = new Available_Time__c();
            cust.Course__c = i.id;
            cust.Date_Time__c = dt;
            cList.add(cust);

            //Advanced dt by 5 minutes
            dt = dt.addMinutes(5);
        }
        myDate = myDate.addDays(1);
    }
    insert cList;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .