0

What is the best way to schedule a job on the current date and time? Will the System.now() function work for that?

0

1 Answer 1

2

Since you cannot do it via the UI you will have to use code or dev console.

As such, no need to use cron at all.

Simply instantiate the batch and execute it.

Database.executeBatch( new batchClassName(), 20);

Change the 20 to whatever size u need

8
  • well firstly I am calling the Scheduler and then in the scheduler Execute function I am doing Database.executeBatch();
    – Malik
    Mar 3, 2017 at 13:19
  • @Malik you are wrong. Not sure I can explain any differently if you do not understand that simply running the code inside the schedule execute method like in my answer is the same as scheduling to run now without the need to mess with cron. Your stuck on wanting to schedule to run now when u do not need to schedule. It's like telling you to set an alarm to eat now. Just eat
    – Eric
    Mar 3, 2017 at 13:43
  • I don't want to call the batch directly....in Schedule i have put batch size
    – Malik
    Mar 3, 2017 at 13:53
  • @Malik forget the schedualeable class. You don't need it for this. All you need to do is execute the batch. You can set the size when you call the batch. See updated answer
    – Eric
    Mar 3, 2017 at 13:54
  • @Eric I am working in sandbox its not working but when I work through schedule it works...
    – Malik
    Mar 3, 2017 at 17:28

You must log in to answer this question.

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