日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Asynchronous Processing Basics || Use Future Methods

發布時間:2025/4/16 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Asynchronous Processing Basics || Use Future Methods 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.



異步處理的主要優點包括:

用戶效率

可擴展性

更高的限制







Use Future Methods



Future methods?

?必須是靜態方法,并且只能返回void類型

指定的參數必須是原始數據類型原始數據類型的數組原始數據類型的集合

不能將標準或自定義對象作為參數

一種常見的模式是向該方法傳遞要異步處理的記錄ID列表





Create an Apex class that uses the @future annotation to update Account records

AccountProcessor.apxc

public class AccountProcessor {@futurepublic static void countContacts(Set<id> setId){List<Account> lstAccount = [select Number_of_Contacts__c,(select id from contacts ) from account where id in :setId ];for( Account acc : lstAccount ){List<Contact> lstCont = acc.contacts ;acc.Number_of_Contacts__c = lstCont.size();}update lstAccount;} }

AccountProcessorTest.apxc

@IsTest public class AccountProcessorTest {public static testmethod void TestAccountProcessorTest(){Account a = new Account(name='Test Account');Insert a;Contact cont = New Contact();cont.FirstName ='Bob';cont.LastName ='Masters';cont.AccountId = a.Id;Insert cont;set<ID> setAccId = new Set<ID>();setAccId.add(a.id);Test.startTest();AccountProcessor.countContacts(setAccId);Test.stopTest();Account ACC = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];System.assertEquals ( Integer.valueOf(ACC.Number_of_Contacts__c) ,1);}}

?

總結

以上是生活随笔為你收集整理的Asynchronous Processing Basics || Use Future Methods的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。