如何在 Salesforce 中插入超过 150 条帐户记录而没有限制例外?
我正在“调试”->“打开执行匿名窗口”选项中运行该语句。我正在尝试插入超过 150 条帐户记录
List<Account> accounts = new List<Account>();
for(Integer i = 0; i < 200; i++)
{
Account account = new Account(Name = 'Test Account');
accounts.add(account);
}
insert accounts; // insert list - counts as 1 DML statement.
,但收到错误消息:
System.LimitException: Too many DML statements: 151
有什么办法可以做到这一点吗?
I am running the statement in the Debug->Open Execute Anonymous Window option. I am trying to insert more than 150 Account records
List<Account> accounts = new List<Account>();
for(Integer i = 0; i < 200; i++)
{
Account account = new Account(Name = 'Test Account');
accounts.add(account);
}
insert accounts; // insert list - counts as 1 DML statement.
But i get the error:
System.LimitException: Too many DML statements: 151
Is there a way i can do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你发布的代码没有任何问题,它是批量化的。
您需要仔细检查调试日志。您可能在 Account 对象上有一个触发器(插入之前、插入之后等),并且其中的某些内容是以次优方式编写的。在循环中创建数据。也许是一个任务?更新一些东西?违反限制的确切堆栈跟踪应该有助于确定它。
如果您没有触发器,仍然可以运行 apex 代码,例如从流程/流程生成器中运行 - 但同样,查看调试& stacktrace 将有助于确定它。
There's nothing wrong with the code you posted, it's bulkified OK.
You need to examine the debug log carefully. You probably have a trigger on Account object (before insert, after insert etc) And something in there is written in suboptimal way. Creating data in a loop. A Task maybe? Updating something? The exact stack trace of where the limit was breached should help to nail it down.
If you don't have a trigger there's still way to run apex code for example from flow/process builder - but again, viewing the debug & stacktrace will help to nail it down.