创建每日,每周和每月的案例记录

时间:2016-02-03 11:37:40

标签: triggers salesforce apex

我需要创建一个案例,我们可以设置一个频率,以便每天,每周和每月自动创建一个新案例记录。

我当时认为需要一个顶点触发器。有谁知道如何做到这一点?

1 个答案:

答案 0 :(得分:1)

如评论中所述,关于为什么需要创建案例的业务流程的信息不多,因此需要扩展以下代码以合并该逻辑

public with sharing class CaseCreatorJob implements Database.Batchable < SObject > , Database.AllowsCallouts {
  public Database.QueryLocator start(Database.BatchableContext bc) {
    System.debug('CaseCreatorJob Started.....!');
    return Database.getQueryLocator('select id from Case where SomethingToGoWith__c = true');
  }

  public void execute(Database.BatchableContext bc, List < Case > cases) {
    list < Case > caseForInsert = new list < Case > ();

    for (Case sb: cases) {
      Case newCase = new Case();

      // update some fields
      caseForInsert.add(newCase);
    }

    insert caseForInsert;
  }

  public void finish(Database.BatchableContext bc) {
    System.debug('CaseCreatorJob Completed.....!');
  }
}

然后,您可以使用管理设置中的APEX计划程序将此批处理设置为按您需要的频率和时间运行。

有关详细信息,请查看https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm