When Dynamics 365 is used to its full enterprise capacity, often a composite operation will span multiple CRUD operations and will need to be executed atomically. Such requirements typically dictate that if any of the operations were to fail, the entire process must roll back to ensure data integrity.
As of Dynamics CRM 2015, ExecuteTransactionRequest
was introduced in the SDK libraries, allowing custom code to execute within a single database-level transaction.
In this recipe, we will create an account and a contact within the scope of a single transaction.
In order to test this code, you will need write access to the account and contact entities, a Visual Studio IDE, and the Dynamics 365 NuGet packages to access the SDK libraries (please refer to the first recipe in this chapter for details on how to set up your Visual Studio solution).