• Sam_India
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

Hi Folks,

 

Requirement: To create a Schedule/Cron/Code job which executes after a specific interval, say after every 1 minute.

 

There is no direct feature in SFDC of doing it but with a tricky way.

Step 1: Create an Apex class which contains the business logic which is required to be executed after specific intervals.

Step 2: Create a Scheduleable Apex Class Like below:

 

global class ScheduleChatter implements Schedulable {
    global void execute(SchedulableContext SC)  {                 

        //The line of code below would contain the required business logic

        TestChatter.initGoogleApp();

        System.debug('-----------ScheduleChatter---------');

        String hour = String.valueOf(Datetime.now().hour());

        String min = String.valueOf(Datetime.now().minute() + 1);

        String ss = String.valueOf(Datetime.now().second()); 

        
String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';

        System.debug('-----------nextFireTime---------' + nextFireTime);

        

ScheduleChatter s = new ScheduleChatter();

         System.schedule('Job Started At ' + String.valueOf(Datetime.now()), nextFireTime, s);

        

}   

}

 

Step 3: This Schedule job is initiated by a code, which can be run on System log screen or via another trigger/class:

ScheduleChatter s = new ScheduleChatter();

String hour = String.valueOf(Datetime.now().hour());

String min = String.valueOf(Datetime.now().minute());

String ss = String.valueOf(Datetime.now().second());

String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';

system.schedule('Start me once', nextFireTime, s); 

 

The Schedulable class will keep on calling itself after every 1 minute and eventually calls the code which is needed to be called after specified interval of time.

 

This code is written as part of R&D.

 

Thanks,

Sam

Hi Folks,

 

Requirement: To create a Schedule/Cron/Code job which executes after a specific interval, say after every 1 minute.

 

There is no direct feature in SFDC of doing it but with a tricky way.

Step 1: Create an Apex class which contains the business logic which is required to be executed after specific intervals.

Step 2: Create a Scheduleable Apex Class Like below:

 

global class ScheduleChatter implements Schedulable {
    global void execute(SchedulableContext SC)  {                 

        //The line of code below would contain the required business logic

        TestChatter.initGoogleApp();

        System.debug('-----------ScheduleChatter---------');

        String hour = String.valueOf(Datetime.now().hour());

        String min = String.valueOf(Datetime.now().minute() + 1);

        String ss = String.valueOf(Datetime.now().second()); 

        
String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';

        System.debug('-----------nextFireTime---------' + nextFireTime);

        

ScheduleChatter s = new ScheduleChatter();

         System.schedule('Job Started At ' + String.valueOf(Datetime.now()), nextFireTime, s);

        

}   

}

 

Step 3: This Schedule job is initiated by a code, which can be run on System log screen or via another trigger/class:

ScheduleChatter s = new ScheduleChatter();

String hour = String.valueOf(Datetime.now().hour());

String min = String.valueOf(Datetime.now().minute());

String ss = String.valueOf(Datetime.now().second());

String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';

system.schedule('Start me once', nextFireTime, s); 

 

The Schedulable class will keep on calling itself after every 1 minute and eventually calls the code which is needed to be called after specified interval of time.

 

This code is written as part of R&D.

 

Thanks,

Sam

I wonder if anyone can help me with a test method for a class that implements Scheduler. It looks like this:

 

 

global class scheduledCreateOpportunity implements Schedulable{
global void execute(SchedulableContext ctx) {
//get all contracts and make a set of their ids
Map<Id, Contract> contracts = new Map<Id, Contract>([Select Id, Name, Account.PriceLevel__c, Account.Id, Related_SLC__r.Id, ContractTerm, Integrator__r.Id, Distributor__r.Id, End_User__r.Id, Representative__r.Id, EndDate
From Contract
Where EndDate =: Date.today()]);
Set<Id> sContIds = contracts.keySet();
....
}
}

 

 It's a pretty big class, but that the end of the day the idea is that it's supposed to create opportunity from a contract at a certain time based on the contract's end date. I know how to write most of the test method, I just don't know how to call the class above correctly, and the page bellow doesn't seem to help :(

 

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_scheduler.htm?SearchType=Stem

 

 I'm not using the CronTrigger, just schedualing this thing to run via front end every day at midnight. Any ideas how I might call the class for testing?

 

Message Edited by Bella on 03-26-2010 07:20 AM
  • March 26, 2010
  • Like
  • 0

Current documents has no example on how to schedule apex jobs every 10 mins. I tried with unix cron job syntax style (like 0,10,20,30,40,50 slots), that doesn't work.

 

Any help would be appreciated.

 

Thanks

  • February 17, 2010
  • Like
  • 0
Hi,


Using Apex Api, I need to create a scheduled workflow programmatically. I downloaded Apex Api locally on my system but where exactly do I need to download the api so that I can call/ use those functions that are already defined in the API. Where do I write a script/ create a cron job. Do I write that in a class. I am clueless.

If somebody can tell me the steps that would be great.  Please let me know at the earliest.


thanks,
kathyani
Hi,

I have a spreadsheet that I would like to import into salesforce.  I am saving the spreadsheet as a csv data file then using the Apex Data Loader to get this into salesforce.  My problem is that I have data from different languages and these seem to appear as question marks (e.g. ???? ???) in salesforce.  If I copy and paste the data straight into salesforce it appears with no problems.

I don't however want to copy and paste 300+ records to get them showing properly.  Is there some way to get these special characters importing correctly using the apex data loader?