【问题标题】:Q>How to fix "DML currently not allowed" when accessing visualforce pageQ>访问visualforce页面时如何修复“当前不允许DML”
【发布时间】:2015-06-29 07:36:58
【问题描述】:

我编辑了我的课程并成功保存,但是当我访问使用该课程的页面时,我收到一个错误

目前不允许使用 DML 发生意外的错误。您的开发组织已收到通知。

这是我的控制器

public class DefinitionController {

    public DefinitionController() {
        this.DefTable();
    }

    public void DefTable() {
        listplatforms = [select Name, Status__c from Platform__c];

        for (Platform__c idlistplatforms : [select Id from Platform__c]) {
            List<Def__c> existplatforms = [select Platform__c from Def__c where Platform__c = :idlistplatforms.Id];

            if (existplatforms.size() > 0) {
                idlistplatforms.Status__c = 'Set';
                //update idlistplatforms;
                System.debug('Found' + idlistplatforms);
            } else {
                idlistplatforms.Status__c = 'Not Set';
                //update idlistplatforms;
                System.debug('Not Found' + idlistplatforms);
            }
            update idlistplatforms;
        }
    }

}

我认为问题出在 update 部分。有人可以编辑我的代码以便我克服这个错误吗?

提前致谢!

【问题讨论】:

    标签: salesforce apex-code apex force.com dml


    【解决方案1】:

    简而言之,类构造函数中不允许进行 DML 操作,因为这可能会导致危险的副作用。

    你可以找到here的好答案

    【讨论】:

      【解决方案2】:

      对不起,伙计,但就像帕维尔说的那样,您不能将 DML 放入构造函数中。

      您可以做的是让视觉强制页面加载,然后使用远程操作调用您的顶点以进行 DML 查询。

      确保在 jquery 的 document.ready 中执行此操作。

      【讨论】:

        猜你喜欢
        • 2015-10-15
        • 2011-07-31
        • 2016-12-01
        • 2020-04-03
        • 2022-07-11
        • 2017-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多