现在位置:
首页 > Salesforce > 正文
salesforce Schedule Jobs用法
- global class deleteANSMessageJob implements Schedulable {
- //Execute method
- global void execute (SchedulableContext SC) {
- DateTime recordDate = DateTime.now().date();
- //recordDate = recordDate.addMonths(-2);
- List<ANS_Message_Repository__c> messages = [select Id from ANS_Message_Repository__c where LastModifiedDate <:recordDate ];
- integer count = messages.size();
- delete messages ;
- system.debug('delete count: '+count);
- }
- }
- @isTest
- private class deleteANSMessageJobTest{
- static testMethod void deleteANSMessageJobTest(){
- Test.startTest();
- //Schedule the test job
- String CRON_EXP = '0 1 * * * ? *';//per 1min
- String jobId = System.schedule('deleteANSMessageJob',CRON_EXP,new deleteANSMessageJob());
- //get current total
- DateTime recordDate = DateTime.now().date();
- //recordDate = recordDate.addMonths(-2);
- List<ANS_Message_Repository__c> messages = [select Id from ANS_Message_Repository__c where LastModifiedDate <:recordDate ];
- integer total = messages.size();
- System.assertEquals(0,total);
- Test.stopTest();
- }
- }
提示:在testclass里做的所有操作(DELETE,UPDATE,CREATE)都不会影响原始数据
cron在线表达式生成:http://cron.qqe2.com/
参考资料:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
https://trailhead.salesforce.com/en/modules/asynchronous_apex/units/async_apex_scheduled
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · Salesforce VisualForce 使用apex:actionFunction调用后台方法
- · How to Call Salesforce API from Lightning Component
- · apex highlight userDefineLang for notepad++
- · 详解 Salesforce 15 和 18 位的ID
- · Salesforce Test class注意事项
- · salesforce Milestone clock is not running
- · salesforce apex traced the number of query
- · salesforce antscript无法拉取完整的profile
- · salesforce lightning report取URL参数
- · salesforce test class用现有数据测试
- · salesforce report get url parameters
- · salesforce display trigger error