Deprecated: Optional parameter $list declared before required parameter $is_script is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 21

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 45

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 104

Deprecated: Optional parameter $expire declared before required parameter $path is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_functions.php on line 54

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/mobilemenu.php on line 147

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 583

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 606

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":846,"date":"2017-07-27T05:32:35","date_gmt":"2017-07-27T05:32:35","guid":{"rendered":"http:\/\/www.salesforcenextgen.com\/?p=846"},"modified":"2020-12-28T19:45:34","modified_gmt":"2020-12-28T19:45:34","slug":"datamanipulationlanguage","status":"publish","type":"post","link":"https:\/\/salesforcenextgen.com\/datamanipulationlanguage\/","title":{"rendered":"Data Manipulation Language"},"content":{"rendered":"

Data Manipulation Language<\/strong><\/p>\n

\u00a0<\/strong><\/p>\n

Data Manipulation Language is the way we perform CRUD operations in the database i.e. create, retrieve, update and delete records in the Salesforce Database.<\/p>\n

<\/p>\n

DML operations are carried on within a transaction, which is either successfully completed or if an error is encountered then the whole transaction is rolled back.<\/p>\n

All operations which can either start in a trigger, apex class method, or anonymous code block. When they run in a transaction they are considered as a single unit of operations.\u00a0 They also include chaining of procedure which is called from inside a transaction operation, for ex a class method updates a record which in turn begins execution of the trigger. They are all part of a single transaction.<\/p>\n

DML consists of following statements.<\/p>\n

    \n
  1. Insert<\/li>\n
  2. Update<\/li>\n
  3. Upsert<\/li>\n
  4. Delete<\/li>\n
  5. Merge<\/li>\n
  6. Undelete<\/li>\n
  7. Converting Leads<\/a><\/li>\n<\/ol>\n

    DML can be performed on a single record or to a batch or collection of records. Salesforce allows only 150 DML iteration per transaction, therefore it is advised that we should perform DML on a collection rather on a single record, it improves the overall execution efficiency of the code.<\/p>\n

    Ex: inefficient code=><\/p>\n

    For(account a: accountlist){<\/p>\n

    If(a.name ==\u201dsomevalue\u201d){<\/p>\n

    a.phone = \u201c9999999999\u201d;<\/p>\n

    }<\/p>\n

    Update a;<\/p>\n

    }<\/p>\n

    Ex: More Efficient code=><\/p>\n

    List<Account> acctoUpdate = new list<Account>();<\/p>\n

    For(account a: accountlist){<\/p>\n

    If(a.name ==\u201dsomevalue\u201d){<\/p>\n

    a.phone = \u201c9999999999\u201d;<\/p>\n

    }<\/p>\n

    acctoUpdate .add(a);<\/p>\n

    }<\/p>\n

    Update acctoUpdate;<\/p>\n

    DML and Database Class methods<\/strong><\/p>\n

    Apex has offered Data manipulation in two ways, DML operations or the use of Database class method.<\/p>\n

    Ex: DML<\/p>\n

    List<Account> accountList =\u00a0new\u00a0List<Account>();<\/p>\n

    accountList.add( new Account(Name=\u201dTest1\u201d));<\/p>\n

    accountList.add( new Account(Name=\u201dTest2\u201d));<\/p>\n

    insert accountList;<\/p>\n

    Database Class<\/p>\n

    List<Account> accountList =\u00a0new\u00a0List<Account>();<\/p>\n

    accountList.add( new Account(Name=\u201dTest1\u201d));<\/p>\n

    accountList.add( new Account(Name=\u201dTest2\u201d));<\/p>\n

    Database.SaveResult[] SaveResultList =\u00a0Database.insert(accountList,\u00a0false);<\/p>\n

    If the parameter passed in the method is true, then it behaves exactly same as the DML insert operation.<\/p>\n

    The main reason to use Database Class over the DML operation is the ability to partially process records if an error is encountered, in DML the whole transaction is roll backed in case of an exception.<\/p>\n

    You can use DML if you want to through Apex Exception immediately interrupting the control flow.<\/p>\n

    Next: \u00a0DML Operation in detail<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

    Data Manipulation Language \u00a0 Data Manipulation Language is the way we perform CRUD operations in the database i.e. create, retrieve, update and delete records in the Salesforce Database.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[40,61,74,45,75,38,42,51,52],"class_list":["post-846","post","type-post","status-publish","format-standard","hentry","category-apexprogramming","tag-apex","tag-dml","tag-dynamic","tag-dynamic-soql","tag-dynamic-sosl","tag-salesforce","tag-salesforce-apex","tag-soql","tag-visualforce"],"_links":{"self":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts\/846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/comments?post=846"}],"version-history":[{"count":3,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts\/846\/revisions"}],"predecessor-version":[{"id":2216,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts\/846\/revisions\/2216"}],"wp:attachment":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/media?parent=846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/categories?post=846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/tags?post=846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}