首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >粗放铅工业再分类

粗放铅工业再分类
EN

Stack Overflow用户
提问于 2015-06-29 18:16:12
回答 1查看 203关注 0票数 0

我正在尝试建立一个工作,我可以运行几次,每天保持我们的线索分类,以满足我们的销售和营销批准名单。我的测试脚本很好用。但是,当我在沙箱中运行它时,我运行的是一堆虚拟数据,我遇到了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个*

代码语言:javascript
复制
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;
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-29 20:23:52

您在for循环中使用DML操作,这会导致错误。只需在for循环之外对DML语句进行模式设置即可。

代码语言:javascript
复制
    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)。

更改此条件,甚至删除它,因为我没有看到任何原因。

代码语言:javascript
复制
    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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31122741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档