{"id":1837,"date":"2026-10-13T09:00:00","date_gmt":"2026-10-13T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/"},"modified":"2026-11-22T11:02:28","modified_gmt":"2026-11-22T05:32:28","slug":"dml-interview-questions-database-class","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/","title":{"rendered":"DML Interview Questions: Database Class and Errors (60+ Q&amp;A)"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">DML Interview Questions check how you save data safely in Apex. Interviewers ask about each statement, the Database class, partial success, rollbacks and the errors that stop a transaction. So expect both theory and &#8220;fix this code&#8221; tasks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Last reviewed for the Winter &#8217;27 release (November 2026).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This is Part 9 of our Salesforce developer interview series. It covers DML statements and Database class methods, from simple to tricky, with short answers. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/dml-operations-in-apex\/\">DML operations in Apex<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-database-class-partial-success\/\">Database class methods and partial success<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-savepoints-and-rollback\/\">savepoints and rollback<\/a>.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What are DML Interview Questions?<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">DML Interview Questions test the Data Manipulation Language in Apex. DML creates, changes and removes records, using statements such as insert and update or methods such as Database.insert. In short, SOQL reads data, while DML writes it.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Think of a notebook. Insert writes a new page, update changes a line, delete tears out a page and undelete tapes it back. Upsert either writes a new page or fixes an old one, depending on whether it exists.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Why DML Interview Questions Matter<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Every save in Apex uses DML, so mistakes here break whole transactions. Here is why DML Interview Questions matter.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>First, DML inside loops is the second most common limit failure.<\/li>\r\n\r\n<li>Also, partial success decides whether one bad row stops everything.<\/li>\r\n\r\n<li>Next, mixed DML errors confuse many developers in tests.<\/li>\r\n\r\n<li>Savepoints let you undo work when a later step fails.<\/li>\r\n\r\n<li>Finally, upsert with external Ids is key for integrations.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">So strong DML answers show you write reliable code.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">How to Prepare for DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Preparing for DML Interview Questions follows five steps. First, learn the six DML statements and what each does. Next, compare DML statements with Database class methods. Then practise reading SaveResult and Database.Error. After that, learn savepoints, mixed DML and the main limits. Finally, write a bulk insert that logs failed rows and explain it aloud.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-1-1024x640.png\" alt=\"DML Interview Questions diagram showing five steps to prepare for DML questions\" class=\"wp-image-1835\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Five steps to prepare for DML questions.<\/figcaption><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">DML Operations at a Glance<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The table below lists every DML operation you must know.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operation<\/th><th>What it does<\/th><th>Database method<\/th><\/tr><\/thead><tbody><tr><td>insert<\/td><td>Creates new records<\/td><td>Database.insert<\/td><\/tr><tr><td>update<\/td><td>Changes existing records<\/td><td>Database.update<\/td><\/tr><tr><td>upsert<\/td><td>Inserts or updates by Id or external Id<\/td><td>Database.upsert<\/td><\/tr><tr><td>delete<\/td><td>Moves records to the Recycle Bin<\/td><td>Database.delete<\/td><\/tr><tr><td>undelete<\/td><td>Restores records from the Recycle Bin<\/td><td>Database.undelete<\/td><\/tr><tr><td>merge<\/td><td>Combines up to three duplicate records<\/td><td>Database.merge<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">DML Statements vs Database Methods<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The table below compares the two styles, a very common question.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>DML statement<\/th><th>Database method<\/th><\/tr><\/thead><tbody><tr><td>Syntax<\/td><td>insert recs<\/td><td>Database.insert(recs, false)<\/td><\/tr><tr><td>Partial success<\/td><td>No, all or none<\/td><td>Yes, with allOrNone false<\/td><\/tr><tr><td>On error<\/td><td>Throws DmlException<\/td><td>Returns results with errors<\/td><\/tr><tr><td>Result<\/td><td>None<\/td><td>SaveResult list<\/td><\/tr><tr><td>Extra options<\/td><td>None<\/td><td>DMLOptions and AccessLevel<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">When to use which is simple. Use DML statements when every row must succeed, while Database methods fit when you want to keep good rows and log bad ones.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-2-1024x640.png\" alt=\"DML Interview Questions diagram comparing DML statements and Database methods\" class=\"wp-image-1836\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">DML statement vs Database method.<\/figcaption><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Basic DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These DML Interview Questions cover the statements and core rules.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on DML Statements<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q1: What is DML in Apex?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">DML is Data Manipulation Language, used to <a href=\"https:\/\/swapnilzambare.com\/blog\/dml-operations-in-apex\/\">insert, update, upsert<\/a>, delete, undelete and merge records. So it is how Apex writes data.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q2: Does insert fill in the record Id?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, after insert the Id field on each record is set. So you can use it right away for child records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: mention using the new IDs straight away for child records. It shows practical use.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q3: What does update need on each record?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The record ID. Without it, Apex throws &#8220;Id not specified in an update call&#8221;.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The ID tells Salesforce which row to change. Usually you query the records first, change fields, then update the list. You can also build a record with just the ID, like new Course__c(Id = courseId, Fee__c = 5000), to update one field without a query.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q4: What does upsert do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It inserts records with no match and updates records with a match. By default, it matches on Id.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can upsert use a lookup to match? No, only ID or an external ID field.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you upsert with an external Id?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Pass the field, such as upsert recs Course__c.Course_Code__c. Then matching uses that field instead of Id.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q6: What happens if an upsert key matches more than one record?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Apex throws an error for that row, because the match is not unique. So mark external Id fields as unique.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say how you prevent it: mark the external ID field as unique.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q7: What does delete do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It moves records to the Recycle Bin, where they stay for 15 days. Then undelete can restore them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Do children get deleted too? Yes for master detail children, and lookups are cleared or blocked based on the field setting.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q8: How do you query deleted records?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use ALL ROWS in Apex, such as SELECT Id FROM Course__c WHERE IsDeleted = true ALL ROWS. So you can find them for undelete.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q9: What does Database.emptyRecycleBin do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It removes records from the Recycle Bin for good, so they can no longer be undeleted.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Pass it the records or IDs, like Database.emptyRecycleBin(oldCourses);. Use it carefully, for example in a clean up job after a legal retention period, because there is no undo.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q10: What is the difference between delete and hard delete?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">delete moves records to the Recycle Bin for 15 days, so they can be undeleted. A hard delete, through Database.emptyRecycleBin or the Bulk API with the hard delete permission, removes them for good.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q11: Which objects support merge?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Leads, contacts, cases and accounts. Also, one call merges up to three records into one master.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Database Class Methods<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">DML Interview Questions on the Database class focus on partial success and result objects.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q12: What is allOrNone?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It is the second argument of Database methods. When false, <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-database-class-partial-success\/\">good rows save<\/a> and bad rows return errors.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q13: What does Database.insert return?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A List of Database.SaveResult, one per record in the same order. So you can match each result to its record.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: stress &#8220;same order&#8221;. You match results to records by index.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you read errors from a SaveResult?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Check isSuccess(), then loop getErrors(). Each Database.Error has getMessage(), getStatusCode() and getFields().<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: What is getFields() for? It lists the fields that caused the error, useful for showing messages next to them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q15: Which result types do other methods return?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Each Database method returns its own result type, one result per record in the same order.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Method<\/th><th>Returns<\/th><th>Useful extra<\/th><\/tr><\/thead><tbody><tr><td>Database.insert \/ update<\/td><td>SaveResult<\/td><td>getId() for new IDs<\/td><\/tr><tr><td>Database.upsert<\/td><td>UpsertResult<\/td><td>isCreated() to tell insert from update<\/td><\/tr><tr><td>Database.delete<\/td><td>DeleteResult<\/td><td>getId() of the deleted record<\/td><\/tr><tr><td>Database.undelete<\/td><td>UndeleteResult<\/td><td>getId() of the restored record<\/td><\/tr><tr><td>Database.merge<\/td><td>MergeResult<\/td><td>getMergedRecordIds()<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q16: How do you know if upsert inserted or updated a row?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Call isCreated() on the UpsertResult. It returns true for inserts and false for updates.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: count how many new courses an integration created and how many it updated, and write both numbers to a log record after each nightly run.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q17: What is the default value of allOrNone?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">True, so one failed row rolls back the whole call. Therefore, pass false only when you handle errors.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: many candidates think Database methods default to partial success. They do not.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q18: Can a DML statement give partial success?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. DML statements like insert and update are always all or none.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If one record fails, the whole statement fails and nothing in it is saved. For partial success, use Database.insert(records, false) and read each SaveResult.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q19: What is Database.DMLOptions?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It sets extra save options, such as allowFieldTruncation or assignment rules. For example, run lead assignment rules on insert.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How do you send the default assignment email? Set emailHeader.triggerUserEmail = true on the options.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you run DML in user mode?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use insert as user recs, or pass <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-crud-and-fls-user-mode\/\">AccessLevel.USER_MODE<\/a> to a Database method. Then object, field and sharing rules apply.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q21: What is the difference between insert and Database.insert?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">insert is a statement that is all or none and throws a DmlException on the first failure. Database.insert is a method that can take allOrNone false, saves the good rows and returns a SaveResult for each record. Use insert when one failure should stop everything.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q22: What does Database.convertLead do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It converts leads into accounts, contacts and optional opportunities. Also, it returns LeadConvertResult objects.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Intermediate DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These DML Interview Questions cover limits, exceptions and transaction control.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on DML Limits<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q23: How many DML statements can a transaction run?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/swapnilzambare.com\/blog\/apex-governor-limits-explained\/\">150 DML statements per transaction<\/a>. Never put DML inside a loop.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>DML limit<\/th><th>Per transaction<\/th><\/tr><\/thead><tbody><tr><td>DML statements<\/td><td>150<\/td><\/tr><tr><td>Rows processed by DML<\/td><td>10,000<\/td><\/tr><tr><td>Object types in one mixed list<\/td><td>10<\/td><\/tr><tr><td>Savepoints and rollbacks<\/td><td>Count as DML statements<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q24: How many rows can DML process in a transaction?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">10,000 rows across all DML calls in the transaction.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Inserting 200 records counts as 200 rows but only one statement. For larger volumes, use Batch Apex so each chunk gets its own limits.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q25: Does a list of 200 records count as one statement?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, one insert of a list counts as one statement and 200 rows. So bulk DML saves statements.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How many rows does an empty list update use? None, and it does not count as a statement either.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q26: Do savepoints count against limits?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, setSavepoint and rollback each count as a DML statement. So use them carefully in loops.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: this is a rarely known fact. Saying it shows real depth.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q27: Can you insert different object types in one call?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, a List&lt;SObject&gt; can hold up to ten types. However, records are grouped into chunks by type.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q28: Does DML on an empty list count toward limits?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. Apex skips DML on an empty list without using a statement or rows. Checking isEmpty() first is still a good habit, because it makes the code&#8217;s intent clear.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q29: How do you check DML usage in code?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use Limits.getDmlStatements() and Limits.getDmlRows(). Then compare with the limit methods.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on DML Exceptions<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q30: What exception does a failed DML statement throw?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/swapnilzambare.com\/blog\/apex-exception-handling-custom-exceptions\/\">A DmlException<\/a>. Its methods tell you which row failed and why.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">getNumDml() gives how many rows failed, getDmlIndex(i) gives each row&#8217;s position in your list, and getDmlMessage(i) gives the error text. Example: catch (DmlException e) { System.debug(e.getDmlMessage(0)); }<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q31: How do you show a friendly error on a record in a trigger?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Call addError on the record, such as rec.addError(&#8216;Fee must be positive&#8217;). So the save stops with that message.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q32: What is the &#8220;Mixed DML operation&#8221; error?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It happens when one transaction changes setup objects, such as User, and non-setup objects, such as Account. Salesforce blocks this for security.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name the two common fixes, System.runAs in tests and async in code.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q33: How do you fix mixed DML in a test?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Do the setup DML, like inserting the User, inside System.runAs.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">System.runAs runs that block in a separate context, so the user insert and the account insert no longer clash. Example: System.runAs(new User(Id = UserInfo.getUserId())) { insert testUser; } then insert the account outside the block.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q34: How do you fix mixed DML in normal code?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Move one part to a future or Queueable method. So the two DML types run in separate transactions.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can a Queueable fix mixed DML? Yes, it runs the second DML in its own transaction.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q35: What does &#8220;INVALID_CROSS_REFERENCE_KEY&#8221; mean?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A lookup points to a record that does not exist or that you cannot see. So check the Id and access.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q36: What does &#8220;UNABLE_TO_LOCK_ROW&#8221; mean?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Another transaction holds a lock on the record or its parent. For example, two jobs update children of one account.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: connect lock errors to data skew. Interviewers look for that link.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q37: What does &#8220;FIELD_CUSTOM_VALIDATION_EXCEPTION&#8221; mean?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A validation rule blocked the save. The rest of the message is the rule&#8217;s error text. Fix the data, or handle the error and show it to the user; never switch off validation rules from code.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q38: How do you reduce lock errors?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Sort records by parent Id, keep transactions short and retry failed rows. Also, avoid <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-large-data-volumes\/\">data skew<\/a> on one parent.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Savepoints and Rollback<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q39: What is a savepoint?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/swapnilzambare.com\/blog\/apex-savepoints-and-rollback\/\">A marker in the transaction<\/a> that you can roll back to. So you undo DML after it while keeping earlier work.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q40: How do you use a savepoint?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Savepoint sp = Database.setSavepoint(); then Database.rollback(sp) in a catch block. As a result, partial work is undone.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q41: Does rollback reset record Ids in memory?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No, inserted records keep their Ids in memory after rollback. So clear or clone them before inserting again.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: this leads to the next trick question about retries, so mention cloning the records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q42: Does rollback undo static variables?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. Static variables and other values in memory keep their changes. Only database changes are undone.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">So a recursion flag set before the rollback stays set. Reset any static state yourself if you plan to retry the work.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q43: Can you roll back to the same savepoint twice?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, but only while it is still valid. Rolling back to an earlier savepoint makes every later savepoint invalid, and using an invalid one throws an error.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q44: Can you roll back a callout?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No, rollback only undoes database changes. Also, a callout after uncommitted DML throws an error.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Advanced DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These DML Interview Questions cover design, async options and special cases.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Advanced DML Behaviour<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q45: When do DML changes become permanent?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">At the end of the transaction, when Salesforce commits. If an unhandled exception occurs, everything rolls back.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can you commit halfway through a transaction? No, Apex has no manual commit.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q46: Does DML fire triggers and flows?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, DML runs the <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-order-of-execution-developers\/\">full save order<\/a>, including triggers, validation rules and flows. So one insert can start much more work.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q47: What happens to triggers with partial success?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If some rows fail, Salesforce rolls back and retries the good rows. So triggers can fire more than once, and static variables are not reset.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say triggers can run twice with partial success. It explains many odd bugs.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q48: What fields cannot be written with DML?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">System fields such as CreatedDate, formula fields and roll-up summary fields. However, data migration can set audit fields with a special permission.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q49: How do you insert parent and child in one call?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use an external Id reference on the child, such as a parent instance with only the external Id set. Then one insert can link them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: What must the parent reference include? Only the external ID field value, nothing else.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q50: What does allowFieldTruncation do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It cuts text that is too long instead of failing. By default, long strings cause an error.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q51: How do you skip duplicate rules in Apex?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use DMLOptions.DuplicateRuleHeader.allowSave = true. So records save even when a rule flags them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q52: What are Database.insertAsync and insertImmediate?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">They write to external objects. insertAsync queues the write, while insertImmediate writes right away.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q53: What is the order of DML when inserting parents and children?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Insert parents first, so they get IDs, then set the lookup on each child and insert the children. With external ID references you can do both in one call, but the parent still saves before the child.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q54: Why should you avoid DML in constructors of Visualforce controllers?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">DML is not allowed during page load in a controller constructor. So run it in an action method instead.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: mention the action attribute on apex:page as the place for page load work.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Bulk DML Design<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q55: How do you bulkify DML in a loop?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Add records to a List inside the loop, then <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-bulkification-best-practices\/\">run one DML after it<\/a>. So one statement covers all rows.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q56: How do you update records from a Map?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Call update map.values().<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">values() returns a List, so it works directly with DML. Because a Map holds each ID once, this also avoids the &#8220;Duplicate id in list&#8221; error when the same record was changed in several places.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q57: What error appears when a list has the same Id twice?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">&#8220;Duplicate id in list&#8221;. It happens when the same record appears twice in one DML list.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Collect records in a Map&lt;Id, SObject&gt; first, so later changes to the same ID replace the earlier entry, then update map.values().<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q58: How do you handle 50,000 updates?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/swapnilzambare.com\/blog\/batch-apex-start-execute-finish\/\">Use Batch Apex<\/a>, often with 200 records per execute. Each chunk gets fresh DML limits.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">50,000 updates in one transaction would pass the 10,000 DML row limit. Batch Apex splits the work into 250 chunks of 200, and the finish method can email a summary of failures.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q59: How do you update thousands of records without hitting lock errors?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Sort the records by parent ID before updating, keep batch sizes moderate, and avoid running two jobs on the same parents at the same time. Retry failed rows once after a short delay.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q60: What is a unit of work pattern?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It collects all DML in one class and commits it at the end in the right order. For example, the <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-enterprise-patterns-service-selector\/\">fflib Unit of Work<\/a> does this.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Scenario-Based DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Scenario-based DML Interview Questions test whether you can fix real failures.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Design Scenarios<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q61: An integration sends 5,000 course rows daily. How do you save them?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use Database.upsert with an external Id and allOrNone false. Then <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-error-logging-framework\/\">log failed rows<\/a> to a custom object.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name the three parts: upsert, external ID, error log.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q62: A process must create an order and its lines, or nothing. How?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Set a savepoint, insert both, and roll back in the catch block. So no half-saved orders remain.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q63: Users must see field errors on the screen. How do you report them?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use addError in a trigger or validation rule. Also, return Database.Error messages from LWC Apex methods.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How does an LWC show the error? Throw an AuraHandledException with the message, and the component shows it in a toast.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q64: You must assign leads with assignment rules from Apex. How?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Set DMLOptions.assignmentRuleHeader.useDefaultRule = true and call setOptions on each lead. Then insert the leads.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q65: An LWC must save a record and its line items together. How do you design the Apex?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Write one @AuraEnabled method that takes the parent and children, sets a savepoint, inserts the parent, links and inserts the children, and rolls back on error. Return a clear message with AuraHandledException so the user knows what failed.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q66: A test creates a user and an account and fails. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It is a mixed DML error. So create the user inside System.runAs.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: System.runAs(new User(Id = UserInfo.getUserId())) { insert newUser; } then create the account outside the runAs block.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Fixing Code<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q67: Code updates each record inside a for loop. What is wrong?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It runs one DML per record and hits 150 statements. Instead, collect records and update once.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q68: A batch fails because one bad row stops all 200. How do you fix it?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use Database.update(recs, false) and log errors from each SaveResult. So good rows still save.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: add that the job should report failures, not just skip them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q69: A retry after rollback fails with &#8220;cannot specify Id in an insert call&#8221;. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The records kept their Ids after rollback. So clone them without Ids, or set Id to null, before retrying.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q70: A callout after an insert throws &#8220;You have uncommitted work pending&#8221;. How do you fix it?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Make the callout first, or move it to a <a href=\"https:\/\/swapnilzambare.com\/blog\/queueable-apex-chaining-finalizers\/\">Queueable job<\/a>. So DML and the callout do not clash.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q71: A trigger&#8217;s update on related records fails for one record and the user&#8217;s save fails too. How do you avoid that?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use Database.update(related, false) so one bad related record does not block the user&#8217;s save, log the failures, and notify an admin. Use all or none only when the related update must succeed for the save to make sense.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q72: Nightly jobs fail with UNABLE_TO_LOCK_ROW. What do you change?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Sort records by parent, use smaller batches and add a retry. Also, check for one parent with too many children.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">A Real DML Interview Questions Answer<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A classic live task is &#8220;insert enrolments, keep the good rows and log the bad ones&#8221;. Here is a strong answer.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>List&lt;Enrolment__c&gt; rows = buildEnrolments();\r\nList&lt;Database.SaveResult&gt; results =\r\n    Database.insert(rows, false, AccessLevel.USER_MODE);\r\n\r\nList&lt;Error_Log__c&gt; logs = new List&lt;Error_Log__c&gt;();\r\nfor (Integer i = 0; i &lt; results.size(); i++) {\r\n    if (!results[i].isSuccess()) {\r\n        for (Database.Error err : results[i].getErrors()) {\r\n            logs.add(new Error_Log__c(\r\n                Record_Name__c = rows[i].Name,\r\n                Message__c = err.getStatusCode() + ': ' + err.getMessage()\r\n            ));\r\n        }\r\n    }\r\n}\r\nif (!logs.isEmpty()) {\r\n    insert logs;\r\n}<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Explain that allOrNone false keeps the good rows. Next, the index links each result to its record, and errors go to a log object in one insert. So the code uses only two DML statements.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Common Mistakes with DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Putting DML statements inside loops.<\/li>\r\n\r\n<li>Using DML statements when partial success is needed.<\/li>\r\n\r\n<li>Ignoring the SaveResult list after a Database call.<\/li>\r\n\r\n<li>Retrying inserts on records that kept their Ids.<\/li>\r\n\r\n<li>Mixing setup and non-setup DML in one transaction.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Best Practices for Answering DML Interview Questions<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Name the right method and say why, statement or Database class.<\/li>\r\n\r\n<li>Mention the 150 statement and 10,000 row limits.<\/li>\r\n\r\n<li>Show error handling with SaveResult in code.<\/li>\r\n\r\n<li>Use user mode for DML that runs for end users.<\/li>\r\n\r\n<li>Add a savepoint when several steps must succeed together.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_dml_section.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Working with Data in Apex (Apex Developer Guide)<\/a><\/li>\r\n\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_methods_system_database.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Database Class (Apex Reference Guide)<\/a><\/li>\r\n\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_gov_limits.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Execution Governors and Limits<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>DML Interview Questions cover statements, Database methods, errors and limits.<\/li>\r\n\r\n<li>DML statements are all or none, while Database methods allow partial success.<\/li>\r\n\r\n<li>A transaction allows 150 DML statements and 10,000 rows.<\/li>\r\n\r\n<li>Savepoints undo database work, but not Ids or static variables.<\/li>\r\n\r\n<li>Fix mixed DML with System.runAs in tests or async code elsewhere.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Next, continue with <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-trigger-interview-questions\/\">Apex trigger interview questions<\/a>, Part 10 of the series.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>DML Interview Questions check how you save data safely in Apex. Interviewers ask about each statement, the Database class, partial success, rollbacks and the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1834,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[250,8,90],"tags":[98,26,91,105],"swapz_series":[],"class_list":["post-1837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-interview-questions","category-salesforce","category-salesforce-interview","tag-apex","tag-intermediate","tag-interview-questions","tag-soql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DML Interview Questions and Database Class Answers<\/title>\n<meta name=\"description\" content=\"DML Interview Questions with answers: insert, upsert, merge, Database methods, allOrNone, SaveResult, savepoints, mixed DML, limits and scenarios.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DML Interview Questions and Database Class Answers\" \/>\n<meta property=\"og:description\" content=\"DML Interview Questions with answers: insert, upsert, merge, Database methods, allOrNone, SaveResult, savepoints, mixed DML, limits and scenarios.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-13T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-22T05:32:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"DML Interview Questions: Database Class and Errors (60+ Q&amp;A)\",\"datePublished\":\"2026-10-13T03:30:00+00:00\",\"dateModified\":\"2026-11-22T05:32:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/\"},\"wordCount\":3695,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dml-interview-questions-database-class-featured.png\",\"keywords\":[\"Apex\",\"Intermediate\",\"Interview Questions\",\"SOQL\"],\"articleSection\":[\"Developer Interview Questions\",\"Salesforce\",\"Salesforce Interview\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/\",\"name\":\"DML Interview Questions and Database Class Answers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dml-interview-questions-database-class-featured.png\",\"datePublished\":\"2026-10-13T03:30:00+00:00\",\"dateModified\":\"2026-11-22T05:32:28+00:00\",\"description\":\"DML Interview Questions with answers: insert, upsert, merge, Database methods, allOrNone, SaveResult, savepoints, mixed DML, limits and scenarios.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dml-interview-questions-database-class-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dml-interview-questions-database-class-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"DML Interview Questions featured image: title card with a sample interview question and answer\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dml-interview-questions-database-class\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DML Interview Questions: Database Class and Errors (60+ Q&amp;A)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DML Interview Questions and Database Class Answers","description":"DML Interview Questions with answers: insert, upsert, merge, Database methods, allOrNone, SaveResult, savepoints, mixed DML, limits and scenarios.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/","og_locale":"en_US","og_type":"article","og_title":"DML Interview Questions and Database Class Answers","og_description":"DML Interview Questions with answers: insert, upsert, merge, Database methods, allOrNone, SaveResult, savepoints, mixed DML, limits and scenarios.","og_url":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-13T03:30:00+00:00","article_modified_time":"2026-11-22T05:32:28+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"DML Interview Questions: Database Class and Errors (60+ Q&amp;A)","datePublished":"2026-10-13T03:30:00+00:00","dateModified":"2026-11-22T05:32:28+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/"},"wordCount":3695,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-featured.png","keywords":["Apex","Intermediate","Interview Questions","SOQL"],"articleSection":["Developer Interview Questions","Salesforce","Salesforce Interview"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/","url":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/","name":"DML Interview Questions and Database Class Answers","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-featured.png","datePublished":"2026-10-13T03:30:00+00:00","dateModified":"2026-11-22T05:32:28+00:00","description":"DML Interview Questions with answers: insert, upsert, merge, Database methods, allOrNone, SaveResult, savepoints, mixed DML, limits and scenarios.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dml-interview-questions-database-class-featured.png","width":2400,"height":1260,"caption":"DML Interview Questions featured image: title card with a sample interview question and answer"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"DML Interview Questions: Database Class and Errors (60+ Q&amp;A)"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1837"}],"version-history":[{"count":2,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1837\/revisions"}],"predecessor-version":[{"id":3511,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1837\/revisions\/3511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1834"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1837"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}