DEV2 まとめ

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

      ↓

   Continuation クラス

public class AsyncExecutionExample implements Queueable {
    public void execute(QueueableContext context) {
        Account a = new Account(Name='Acme',Phone='(415) 555-1212');
        insert a;        
    }
    System.enqueueJob(new SecondJob());
}

TestClass

@isTest
public class AsyncExecutionExampleTest {
    static testmethod void test1() {
        // startTest/stopTest block to force async processes 
        //   to run in the test.
        Test.startTest();        
        System.enqueueJob(new AsyncExecutionExample());
        Test.stopTest();
        
        // Validate that the job has run
        // by verifying that the record was created.
        // This query returns only the account created in test context by the 
        // Queueable class method.
        Account acct = [SELECT Name,Phone FROM Account WHERE Name='Acme' LIMIT 1];
        System.assertNotEquals(null, acct);
        System.assertEquals('(415) 555-1212', acct.Phone);
    }
}
发布了423 篇原创文章 · 获赞 30 · 访问量 42万+

猜你喜欢

转载自blog.csdn.net/neusoft06/article/details/102835758