Reproducing concurrency problems in Apex
Let's try to understand and reproduce a concurrency issue in Salesforce. In this chapter, we will take an example of a nonprofit firm, which is funded by many corporates. The fund information is saved in a custom object named fund account. This nonprofit company is in the process of going online and currently does not support a fund transfer using online payment gateways. Interested volunteers of different companies need to call the organization's contact number to provide information about their contributions. The custom object fund account stores the aggregated contributions of all the employees of a company. Now, the foundation has been set up; let's look at a simple case of a concurrency issue.
The following figure shows the schema of the custom object fund account:
Two employees of the company ABC call the customer service of this nonprofit organization at the same time. The already available fund of the company ABC is $10,000 and both the...