gpt4 book ai didi

salesforce - Salesforce 中的预定批处理流程

转载 作者:行者123 更新时间:2023-12-01 01:19:53 25 4
gpt4 key购买 nike

我正在尝试实现批处理。我需要一些关于如何测试的帮助/指导。我在这里所做的只是在调试日志中显示机会名称。但是当我在 Apex 测试执行中运行 scheduleBatchable 类时,它也有测试类。未显示 Opp_BatchProcess 上的调试语句。我做错了什么?

这是我的代码

global class Opp_BatchProcess implements Database.Batchable < sObject >
{
globalDatabase.QueryLocator start(Database.BatchableContextBC)
{
system.debug('Insidestart');
returnDatabase.getQueryLocator('select name,id from opportunity');
}

global void execute(Database.BatchableContext BC, List <sObject> batch)
{
for (Sobject s : batch)
{
opportunity o = (opportunity)s;
system.debug('Opp name is' + o.name);
}
}

global void finish(Database.BatchableContext BC) {}
}

我也有一个可安排的类(class)
global class scheduledBatchable implements Schedulable
{
global void execute(SchedulableContext sc)
{
Opp_BatchProcess b = new Opp_BatchProcess();
ID myBatchJobID = database.executebatch(b);
}

public static testMethod void testscheduleMerge()
{
Test.startTest();
scheduledBatchable s8 = new scheduledBatchable();
string sch = '0 0 * * 1-12 ? *';
system.schedule('Process Trans 1', sch, s8);
Test.stopTest();
}
}

最佳答案

看起来您的 testmethod 只测试 Scheduable 类。您还需要测试 Batchable 类。

尝试这个:

global class scheduledBatchable implements Schedulable
{
global void execute(SchedulableContext sc)
{
Opp_BatchProcess b = new Opp_BatchProcess();
ID myBatchJobID = database.executebatch(b);
}

public static testMethod void testscheduleMerge()
{
Test.startTest();
scheduledBatchable s8 = new scheduledBatchable();
string sch = '0 0 * * 1-12 ? *';
system.schedule('Process Trans 1', sch, s8);
Test.stopTest();
}

public static testMethod void testBatchMerge()
{
Test.startTest();
Opp_BatchProcess b = new Opp_BatchProcess();
ID myBatchJobID = database.executebatch(b);
Test.stopTest();
}
}

关于salesforce - Salesforce 中的预定批处理流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10068891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com