Salesforce Apex 并发建议

发布于 2024-10-01 06:51:39 字数 346 浏览 8 评论 0原文

我有一个正在运行的入站电子邮件处理程序。然而,现在我担心并发问题,当用户同时为同一个对象发送两封电子邮件时。 (我有一个业务文档表单和一个发送给 salesforce 的技术文档表单。)它们包含不同的内容,除了公司名称(它们是从其他人直接发送给 salesforce 的)。

由于我在最后插入自定义对象,因此我担心并发问题。这会发生吗?我的入站电子邮件处理程序为同一家公司创建了 2 个自定义对象,并且都只填写了一半的信息。

如果是这样,我该如何防止并发问题的发生? 目前的想法: - 立即使用关联帐户而不是在最后查询 custom_object。如果 custom_object 不存在,请创建一个。

干杯,

I have an inbound email handler that's working. However, right now I'm worried about concurrency issues, when a user sends 2 emails at the same time for the same object. (I have a business document form, and a technical document form that gets sent to salesforce.) They contain different things, except for the company name (They get sent over from someone else directly to salesforce).

Since I'm doing an insert of my custom object at the very end, I'm worried about concurrency issues. Will this ever happen? My inbound email handler creates 2 custom objects for the same company and both filling in only half the information.

If so, how can I prevent a concurrency problem from happening?
Current Ideas:
- Do a query for custom_object right away with the associated account rather than at the very end. If the custom_object does not exist, create one.

Cheers,

Kuen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉酒的小男人 2024-10-08 06:51:39

传统意义上的“并发”在平台上很少成为问题。您的每一封入站电子邮件都将在平台上创建一个单独的进程(处理程序)并独立运行。如果您希望将它们结合起来,您有几个选项来处理多部分电子邮件场景:

  1. 可调度的 Apex 将允许您定期(每天、每周等)检查现有帐户是否存在两个自定义对象,然后使用标准合并将它们组合在一起。缺点是您的用户可能会看到这两个对象,直到您的进程有时间合并它们。将其视为“垃圾收集器”或“清洁过程”类型的模型。
  2. 您可以使用一种入站电子邮件类型作为“主”表单,然后以异步方法处理另一种类型(例如技术文档)。您将增加按正确顺序处理它们的机会,但不能保证。
  3. 您的方式(首先查询)也完全没问题,但同样,您的查询可能无法在插入对象后“捕获”对象,如果没有,您将完全错过它。

站在你的立场上,我可能会先组合 2 个,然后再组合 3 个来清除你错过的任何内容。

"Concurrency" in the traditional sense, is rarely an issue on the platform. Each one of your in-bound emails is going to create a separate process (handler) on the platform and operate independently. You have a couple of options to deal with your multi-part email scenario though if you're looking to combine them:

  1. Schedulable Apex will allow you to regularly (daily, weekly, whatever) check your existing accounts for the existence of two custom objects, then use a standard merge to bring them together. The downside is your users may see both objects until your process has had time to merge them. Think of it as a 'garbage collector' or 'cleaning process' type of model.
  2. You can use one inbound email type as the 'main' form, then process the other (say, the tech doc) in an asynchronous method. You'll up your chances of having them process in the correct order, but there's no guarantee.
  3. Your way (query first) is also completely fine, though again, your query may not 'catch' the object after its been inserted, and if not, you'll miss it entirely.

In your shoes, I'd probably do a combination of 2, and then 3 to clean up any you miss.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文