编写一个可被计划执行的Batch Apex
- 9月
- 26
- Posted by Lin
- Posted in APEX, Salesforce
To use batch Apex, you have to create an Apex class that implements interface Database.Batchable in Salesforce, like the following sample code:
After this is done, you can monitor or manage the execution of it using the Salesforce user interface, from Setup / Jobs / Scheduled Jobs
Here are some examples of schedule expression.
More informations you can reference
HERE
So far, we have created a schedulable batch apex that implements Database.Batchable<sObject> in Salesforce.
But this kind of batch Apex only supports sObject queries and results in start execution, and if you want to use SOQL having aggregate functions like SUM(), MAX(), COUNT(), you can solve it by following this post 《Using Aggregate SOQL queries/results in Batch Apex》 !
Enjoy it!
Execute batch
Then you can use Database.executebatch method to execute it.Schedule Apex job
To schedule your batch Apex to run at regular intervals, you also need an Apex class that implements interface Schedulable, like the following sample code:Schedule Apex via user interface
Click “Schedule Apex” button in Setup / Develop / Apex Classes to create a schedule apex job.After this is done, you can monitor or manage the execution of it using the Salesforce user interface, from Setup / Jobs / Scheduled Jobs
Schedule Apex job via Apex code
Or you can execute a schedulable Apex class with System.schedule method.Here are some examples of schedule expression.
Expression | Description |
---|---|
0 0 13 * * ? | Class runs every day at 1 PM. |
0 0 22 ? * 6L | Class runs the last Friday of every month at 10 PM. |
0 0 10 ? * MON-FRI | Class runs Monday through Friday at 10 AM. |
0 0 20 * * ? 2010 | Class runs every day at 8 PM during the year 2010. |
So far, we have created a schedulable batch apex that implements Database.Batchable<sObject> in Salesforce.
But this kind of batch Apex only supports sObject queries and results in start execution, and if you want to use SOQL having aggregate functions like SUM(), MAX(), COUNT(), you can solve it by following this post 《Using Aggregate SOQL queries/results in Batch Apex》 !
Enjoy it!
近期文章
- Salesforce DevTools Release Notes (version 3.10.0) – mass edit custom fields on lightning
- Salesforce DevTools Release Notes (version 3.9.0)- Object Fields, SOQL Query Editor
- Salesforce DevTools Release Notes (version 3.8.0)
- Salesforce DevTools的开发者用户突破10,000名!THANK YOU!
- Lightning Component中使用Promise处理Apex服务端请求
Top Posts
- Salesforce DevTools – Saleforce开发者必备Chrome扩展 - 222.8K views
- Date format 与 DateTime format - 206.9K views
- Salesforce批量编辑 (Chrome扩展) – 在任何标准视图上进行批量插入, 拷贝, 更新, 删除, 支持Classic与Lightning! - 159.6K views
- 用Sublime Text 3架设Salesforce的快速开发环境 - 122.7K views
- 编写一个可被计划执行的Batch Apex - 121.7K views
分类目录
- APEX
- 应用
- Custom Label
- Custom Metadata
- Custom Setting
- Design & UI
- 交流会
- Heroku
- iOS & Object-c
- Lightnint Component
- Linux & Mac OS
- Metadata API
- Node.js
- Open Source
- Other
- PHP Framework
- Release Notes
- REST API
- Salesforce
- Salesforce DevTools
- Salesforce DX
- SOQL
- Tooling API
- Unit Tests
- Validation Rule
- Visualforce
- WordPress
您必须登录才能发表评论。