DATA-ARCHITECT practice question 17 of 35

A customer is facing locking issued when importing large data volumes of order records that are children in a master-detail relationship with the Account object. What is the recommended way to avoid locking issues during import?

Full set: 257 questions
Answer options
A: Import Account records first followed by order records after sorting order by OrderID.
B: Import Account records first followed by order records after sorting orders by AccountID. Correct answer
C: Change the relationship to Lookup and update the relationship to master-detail after import.
D: Import Order records and Account records separately and populate AccountID in orders using batch Apex.
Correct Answer:
B. Import Account records first followed by order records after sorting orders by AccountID.
Explanation

When importing child records in a master-detail relationship, Salesforce places a lock on the parent record to update system fields, such as roll-up summaries. If child records for many different parents are interleaved in the import file, Salesforce repeatedly locks and unlocks different parent records, causing lock contention and failures. Sorting the child records by the parent ID (AccountID) ensures that all records for a single parent are processed in a contiguous block. This minimizes the number of times the parent record is locked, significantly reducing contention and preventing locking errors during a large data import.

Why Incorrect

A. Import Account records first followed by order records after sorting order by OrderID: Sorting by the child record's ID (OrderID) has no impact on parent record locking; the grouping must be by the parent ID.
C. Change the relationship to Lookup and update the relationship to master-detail after import: This is a complex, disruptive schema change and is not the standard, recommended first approach for mitigating lock contention during data loads.
D. Import Order records and Account records separately and populate AccountID in orders using batch Apex: This adds unnecessary complexity and an extra processing step. Standard data loading tools can handle this correctly if the data is sorted.

References

1. Salesforce Developer Documentation. (2023). Bulk API Developer Guide - Best Practices. "To avoid lock contention on the parent record when you load child records in a master-detail relationship, group the child records by parent ID."

2. Salesforce Architects. (2022). Record Locking Cheatsheet. "To prevent this [parent-child] lock, ensure that your data loading process sorts child records by their parent ID to minimize the number of times a parent record’s lock is acquired and released."

3. Salesforce. (2020). Large Data Volumes [PDF]. p. 12. "When inserting or updating child records in a Master-Detail relationship, the parent record is locked... To avoid this, sort the child records by the parent ID in the CSV file."

Scroll to Top