我正在尝试建立一个工作,我可以运行几次,每天保持我们的线索分类,以满足我们的销售和营销批准名单。我的测试脚本很好用。但是,当我在沙箱中运行它时,我运行的是一堆虚拟数据,我遇到了DML限制的问题。
我正在寻找想法,如何我可以处理尽可能多的线索,尽可能有效。
编辑:
18:00:20.106 (10106660336)|EXCEPTION_THROWN|377|System.LimitException:太多的DML语句: 151 18:00:20.106 (10106789908)|FATAL_ERROR|System.LimitException:太多的DML语句: 151 DML语句数:150个DML行中的151个*
global class Industry_Mappings Implements Schedulable {
Public List < Lead > DisplayIndLeads;
global void execute(SchedulableContext sc) {
DisplayIndLeads = new List < Lead > ();
DisplayIndLeads = [select Industry, Sub_Industry__c from Lead where Sub_Industry__c = null and Industry < > Null and IsConverted < > True];
//This will create a little efficenty with the for loops
Integer skip = 0;
Integer i = 0;
//Advertising and Marketing
List < string > AdvertisingAndMarketing = new List < string > {
'Design', 'Graphic Design', 'Market Research'
};
//List for looping
List < lead > leadstoupdate = new List < Lead > {};
//This starts the Loop for the leads
for (Lead ld : DisplayIndLeads) {
//lead l = (Lead)ld;
//leadstoupdate.size();
//Advertising and Marketing
if (skip == 0) {
for (string AnM : AdvertisingAndMarketing) {
if (ld.Industry == AnM) {
ld.Sub_Industry__c = ld.Industry;
ld.Industry = 'Advertising and Marketing';
skip = 99;
leadstoupdate.add(ld);
}
}
}
System.debug('***** What is in leadstoupdate: ' + leadstoupdate);
update leadstoupdate;
}
}
}发布于 2015-06-29 20:23:52
您在for循环中使用DML操作,这会导致错误。只需在for循环之外对DML语句进行模式设置即可。
for (Lead ld : DisplayIndLeads) {
if (skip == 0) {
for (string AnM : AdvertisingAndMarketing) {
if (ld.Industry == AnM) {
ld.Sub_Industry__c = ld.Industry;
ld.Industry = 'Advertising and Marketing';
skip = 99;
leadstoupdate.add(ld);
}
}
}
}
update leadstoupdate;- --更新-- -
代码只更新一条引线的原因是,在向if (skip == 0)列表添加第一个引线后,您的条件leadsToUpdate为false (因为您将其设置为99)。
更改此条件,甚至删除它,因为我没有看到任何原因。
for (Lead ld : DisplayIndLeads) {
for (string AnM : AdvertisingAndMarketing) {
if (ld.Industry == AnM) {
ld.Sub_Industry__c = ld.Industry;
ld.Industry = 'Advertising and Marketing';
leadstoupdate.add(ld);
}
}
}
update leadstoupdate;https://stackoverflow.com/questions/31122741
复制相似问题