| 1. |
Explain The Apex Data Manipulation Language (dml) Operations? |
|
Answer» Use data manipulation language (DML) operations to insert, update, delete, and restore data in a database. You can execute DML operations using TWO different forms: Apex DML STATEMENTS, such as: insertSObject[] Apex DML database methods, such as: Database.SaveResult[] result = Database.Insert(SObject[]) While most DML operations are available in either form, some exist only in one form or the other. The different DML operation forms enable different types of exception processing: Use DML statements if you want any error that occurs during bulk DML processing to be thrown as an Apex exception that immediately interrupts control flow (by using try. . .catch blocks). This BEHAVIOR is SIMILAR to the WAY exceptions are handled in most database procedural languages. Use DML database methods if you want to allow partial success of a bulk DML operation—if a record fails, the remainder of the DML operation can still succeed. Your application can then inspect the rejected records and possibly retry the operation. When using this form, you can write code that never throws DML exception errors. Instead, your code can use the appropriate results array to judge success or failure. Note that DML database methods also include a syntax that supports thrown exceptions, similar to DML statements. Use data manipulation language (DML) operations to insert, update, delete, and restore data in a database. You can execute DML operations using two different forms: Apex DML statements, such as: insertSObject[] Apex DML database methods, such as: Database.SaveResult[] result = Database.Insert(SObject[]) While most DML operations are available in either form, some exist only in one form or the other. The different DML operation forms enable different types of exception processing: Use DML statements if you want any error that occurs during bulk DML processing to be thrown as an Apex exception that immediately interrupts control flow (by using try. . .catch blocks). This behavior is similar to the way exceptions are handled in most database procedural languages. Use DML database methods if you want to allow partial success of a bulk DML operation—if a record fails, the remainder of the DML operation can still succeed. Your application can then inspect the rejected records and possibly retry the operation. When using this form, you can write code that never throws DML exception errors. Instead, your code can use the appropriate results array to judge success or failure. Note that DML database methods also include a syntax that supports thrown exceptions, similar to DML statements. |
|