1

Is it possible to create a class that will automatically add a record every morning at 9:00am?

The record will have the same data in the fields it just need to automatically insert every morning.

I am only just starting apex so any help would be much appreciated.

Thanks

2 Answers 2

1

Yes, you can create a scheduled apex class to run code at particular point of time. You can check the full details on how to implement a schedule class, set the schedule and finally running it, here.

Your schedule class would look something like this (shamelessly copied from salesforce site) :

global class scheduledBatchable implements Schedulable {
   global void execute(SchedulableContext sc) {
      //call your class here

      NameOfYourCLass myCLass = new NameOfYourClass();
      //call your methods
      myClass.insertRecord();
      // if your logic is very small then you can put that logic right here.
      // another point worth noting is that it is always a best practise to
         call a batch class so that very high volume (>50000) of records 
         can be processed.
   }
}
2
  • 1
    Thanks for this. So do i need to create a class first that would add a record into salesforce, then create another schedule apex class that calls the previous one? I seem to be getting confused how I would achieve this Commented Jan 26, 2015 at 15:30
  • Edited my answer. Hope it helps
    – Sam
    Commented Jan 26, 2015 at 15:38
0

Don't forget about the super awesome process builder! With process builder, you can create records. Without knowing the details, this may be a solution for you without having to write code. If you didn't request the beta version of process builder from your Salesforce rep, you will have it when your Spring 15 release is deployed in your environment. You probably already have it in your Sandbox (assuming you have a sandbox if you're writing code!)

You must log in to answer this question.

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