Asynchronous Apex 04
12930 ワード
🚀 Control Processes with Queueable Apex
スタンバイ電源付きプロセス制御
📚 Learning Objectives
いつでも利用可能(?)
差異:
クエリ可能なApex構文
クエリ可能メソッドベストエクササイズ
📄 Queueable Apex
🎯 Challenge
AddPrimaryContact
public class AddPrimaryContact implements Queueable {
private Contact con;
private String state;
//생성자 생성
public AddPrimaryContact(Contact con, String state) {
this.con = con;
this.state = state;
}
//Queueable 실행장소
public void execute(QueueableContext context) {
LIST<Account> accounts = [Select Id, Name, (Select FirstName, LastName, Id From contacts)
From Account Where BillingState = :state Limit 200];
LIST<Contact> primaryContacts = new LIST<Contact>();
for(Account acc : accounts){
Contact c = con.clone();
c.AccountId = acc.Id;
primaryContacts.add(c);
}
if(primaryContacts.size() > 0){
insert primaryContacts;
}
}
}
AddPrimaryContactTest@isTest
public class AddPrimaryContactTest {
static testmethod void testQueueable(){
LIST<Account> testAccounts = new LIST<Account>();
for(Integer i = 0; i < 50; i++){
testAccounts.add(new Account(Name = 'Account ' + i, BillingState = 'CA'));
}
for(Integer j = 0; j < 50; j++){
testAccounts.add(new Account(Name = 'Account ' + j, BillingState = 'CA'));
}
insert testAccounts;
Contact testContact = new Contact(FirstName = 'John', LastName = 'Doe');
insert testContact;
AddPrimaryContact addit = new addPrimaryContact(testContact, 'CA');
Test.startTest();
System.enqueueJob(addit);
Test.stopTest();
System.assertEquals(50, [Select count() From Contact Where accountId in
(Select Id From Account Where BillingState = 'CA')]);
}
}
🤔 Words
Reference
この問題について(Asynchronous Apex 04), 我々は、より多くの情報をここで見つけました https://velog.io/@wogus0808/Asynchronous-Apex-04テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol