61、Queueable接口
public with sharing class QueueableSample implements Queueable{ private List<String> Name{get;set;} public QueueableSample(List<String> Name){ this.Name = Name; } public void execute(QueueableContext qc){ String sql = 'select Id,Name from Merchandise__c where Name in : Name'; List<Merchandise__c> merchandises = Database.query(sql); for(Merchandise__c merchandise:merchandises){ System.debug(merchandise.Name); } } }
测试方法
@isTest private class Test_QueueableSample { static testMethod void myUnitTest(){ Test.startTest(); List<String> merchandises = new String[]{'Old Laptop','TEST_MERCHANDISE_ITME'}; QueueableSample sample = new QueueableSample(merchandises); ID jobID = System.enqueueJob(sample); Test.stopTest(); } }