+ Start a Discussion
Gaurav AgnihotriGaurav Agnihotri 

Schedulable class

Hi, 
I need to schedule following code:
tempuriOrg.QantelDataServiceEndPoint NewTempUri= new tempuriOrg.QantelDataServiceEndPoint();

      NewTempUri.ProcessWarehouseInventory('username','password');

I was wondering if someone could recommend me the best way to schedule. Should  I create a new class that implements Schedulable 
Any suggestions?
Best Answer chosen by Gaurav Agnihotri
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

You need to use the @future annotation. See http://blog.sforce.com/sforce/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html for an example

Hope this helps

--
Thanks,
Swayam

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hi, 

You can create below Sample Class 
global class Sample_Schdule Implements Schedulable
    {
        global void execute(SchedulableContext sc)
        {
            callSchedule();
        }

        public void callSchedule()
        {
            tempuriOrg.QantelDataServiceEndPoint NewTempUri= new tempuriOrg.QantelDataServiceEndPoint();
             NewTempUri.ProcessWarehouseInventory('username','password');
        }
    }

And Schdule this class either using UI (https://help.salesforce.com/apex/HTViewHelpDoc?id=code_schedule_batch_apex.htm)
or using running below code in Execute anonymous block:
Sample_Schdulep = new Sample_Schdule();
String sch = '0 0 8 13 2 ?';
system.schedule('One Time Pro', sch, p);

Hope this help

--
Thanks,
Swayam
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you.

1) Apex Scheduler
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_scheduling_1.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
global class scheduledMerge implements Schedulable {
   global void execute(SchedulableContext SC) {
      mergeNumbers M = new mergeNumbers(); 
   }
}
The following example uses the System.Schedule method to implement the above class.
scheduledMerge m = new scheduledMerge();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('Merge Job', sch, m);

2) How to Schedule
https://help.salesforce.com/apex/HTViewHelpDoc?id=code_schedule_batch_apex.htm

You can only have 100 active or scheduled jobs concurrently.

3) Scheduling and Monitoring Scheduled Jobs
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_scheduling_3.htm

4) Adding a Test for the Schedulable Class
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_scheduling_2.htm

 
Gaurav AgnihotriGaurav Agnihotri
Hi Guys, 
When I am running this job after making recommeded changes in class, the schedule job is failing with "Aborted" status.

Any idea why?
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

Can your debug log, may be you are getting some exception
 
Gaurav AgnihotriGaurav Agnihotri
I am getting following error message:

Scheduler: failed to execute scheduled job: jobId: 7077A0000040txp, class: common.apex.async.AsyncApexJobObject, reason: Callout from scheduled Apex not supported.

Here is the class:
global  class ScheduleWebService implements Schedulable 
{
	global void execute(SchedulableContext SC) 
  	{
		callSchedule();
  	}
	public void callSchedule()
   	{
      tempuriOrg.QantelDataServiceEndPoint NewTempUri= new tempuriOrg.QantelDataServiceEndPoint();

      NewTempUri.ProcessWarehouseInventory('SalesForceIntegration','password');
   	}
}
Any suggestions?

 
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

You need to use the @future annotation. See http://blog.sforce.com/sforce/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html for an example

Hope this helps

--
Thanks,
Swayam
This was selected as the best answer
Gaurav AgnihotriGaurav Agnihotri
I have modified the class and scheduled it to run. I will update you. Thank you for your help.
Gaurav AgnihotriGaurav Agnihotri
I works Swayan!!
woohoo!!
Thanks everyone.