,

Data integrity

Data integrity is one of the highest virtues of any IT system. You must be able to count on your data reliably reflecting proper values in all scenarios. The Force Platform provides a lot of built-in robustness that protects your data, but whenever anyone is going to write data, you always have the possibility of conflicting user actions causing a loss of data integrity.

The basic unit used to protect data integrity is the transaction. A transaction is an all-or-nothing unit of work. Transactions on the Force Platform, by default, begin when your Apex code issues a DML statement and end when the Apex script that contains them completes. If the script ends without errors, the transaction’s changes to the data commit. If the script does not complete successfully, the changes made by the transaction roll back.

Apex includes the ability to define savepoints. A savepoint is a place within a transaction. You can rollback a transaction to the beginning of the transaction, the default, or to a previously defined savepoint.

You define a savepoint with a method on the Database object, as follows:

Savepoint <name> = Database.setSavepoint();

To roll back to the beginning of a transaction, use the Database.rollback() method. If you include the name of a savepoint as an argument to the method, the transaction rolls back to the specified savepoint.

While a transaction is in progress, the records being used by the transaction are locked. These locks are released when the transaction completes, successfully or unsuccessfully. There might be situations where you want to lock values in a set of records when you initially query the records. For instance, if you are going to transfer values from one financial account to another, you want to lock the values in the original account until they are completely moved to the target account.

You can specifically lock a set of records in a result set by adding the keywords for update to a SOQL query. This approach protects the integrity of your data, but can also cause other processes to wait until the locking transaction completes, so carefully consider the use of these options.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.199.27