在 salesforce 中递归更新 2 个对象上的触发器
我有几个对象(1 个称为约会和事件对象的自定义对象),我正在尝试同步。所以我在每个对象上都有 1 个触发器来搜索和更新记录。问题是,这些触发器将继续递归运行,因为每次更新约会时,事件也会更新,并且触发器不断触发,当然销售人员不接受它。
知道如何克服这个问题吗?
谢谢
I have couple of objects(1 custom object called appointment and event object) which i am trying to syncronize. So i have 1 trigger each on each object which searches and updates the records. The issue is, these triggers will keep running recursively as everytime an appointmet is updated the event is also updated and the triggers keep firing and ofcourse salesforce does not accept it.
Any idea how to overcome this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是让一个包含初始化为 false 的静态布尔变量的 apex 类。然后在每个触发器中,您将检查此变量的状态:
当然,结果是,当其中一个触发器运行时,它将将此变量设置为 true,并阻止递归触发器执行其中包含的任何逻辑if 语句。当然,这仍然会导致一些级联,但只要您不在其中一个触发器中调用另一个更新,它就会停止。
祝你好运!
Easiest way is to have an apex class containing a static boolean variable initialised to false. Then in each of your triggers you would check the state of this variable:
The upshot being, of course, that when one of the triggers runs it'll set this variable to true, and prevent the recursive trigger from executing whatever logic is contained within the if statement. Of course this can still cause some cascading, but it will stop as soon as you don't call another update in one of the triggers.
Good luck!