Question

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

Was it helpful?

Solution

"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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top