2016-06-23 1 views
1

私はApexを初めて使いました。私はすべてのアカウント(何千ものアカウント)に対してWebサービスを呼び出す必要があります。多数のWebサービスコールアウトのスケジュール/バッチ?

通常、単一のWebサービス要求には500〜5000ミリ秒かかります。

このタスクでは、スケジューリング可能なクラスとバッチ可能なクラスが必要です。

私の考えは、アカウントを国コード(ヨーロッパのみ)でグループ化し、すべてのグループに対してバッチを開始することでした。

最初のバッチは、スケジュール可能なクラスによって開始され、次のものは、バッチ仕上げ方法で起動します。

global class AccValidator implements Database.Batchable<sObject>, Database.AllowsCallouts { 

    private List<String> countryCodes; 
    private countryIndex; 

    global AccValidator(List<String> countryCodes, Integer countryIndex) { 
     this.countryCodes = countryCodes; 
     this.countryIndex = countryIndex; 
     ... 
    } 

    // Get Accounts for current country code 
    global Database.QueryLocator start(Database.BatchableContext bc) {...} 

    global void execute(Database.BatchableContext bc, list<Account> myAccounts) { 
     for (Integer i = 0; i < this.AccAccounts.size(); i++) { 
      // Callout for every Account 
      HttpRequest request ... 
      Http http = new Http(); 
      HttpResponse response = http.send(request); 
      ... 
     } 
    } 

    global void finish(Database.BatchableContext BC) { 
     if (this.countryIndex < this.countryCodes.size() - 1) { 
      // start next batch 
      Database.executeBatch(new AccValidator(this.countryCodes, this.countryIndex + 1), 200); 
     } 
    } 

    global static List<String> getCountryCodes() {...} 
} 

そして、私のスケジュールクラス:

global class AccValidatorSchedule implements Schedulable { 
    global void execute(SchedulableContext sc) { 
     List<String> countryCodes = AccValidator.getCountryCodes(); 
     Id AccAddressID = Database.executeBatch(new AccValidator(countryCodes, 0), 200); 
    } 
} 

今I'amはSalesforces実行知事で立ち往生し、制限: ほぼすべてのコールアウトについて、「タイムアウト読み出し」または「コールアウトに割り当てられた最大時間を超過(120000ミリ秒)」という例外が発生します。

また、非同期コールアウトも試みましたが、バッチでは機能しません。

したがって、多数のコールアウトをスケジュールする方法はありますか?

答えて

関連する問題