3

I'm wondering if it is safe to add a lookup that will have >50,000 children under a single parent. The child table has lots of inserts and lots of updates happening in parallel. However, the lookup itself is pretty static. It will not be populated on insert, and only a single transaction at a time will be updating the lookup.

Will lookup skew be a problem on this table?

From what I understand lookup skew is bad because it causes update/insert failures due to row locking issues. The parent record must be locked during update/insert of a child record. If the parent record is not locked then it could be deleted during the update/insert and create a referential integrity issue.

Does the parent record get locked even if the lookup field is not updated?

If the parent record only gets locked when the lookup field is updated, I think that the situation would be safe from lookup skew issues.

https://developer.salesforce.com/blogs/engineering/2013/04/managing-lookup-skew-to-avoid-record-lock-exceptions.html

2

Giving you example, considering Case records, where an account has 50000 cases.

  • If you are not taking AccountId in Case records to update then Salesforce will not lock the account record.

  • If you are inserting Case record with the same accountId then Account record got locked.

  • If you are updating Case with the same AccountId, then Account record got locked.

  • If you are updating Case with different AccountId, then Account record got locked.

Refer: Record Locking Cheat Sheet

Does the parent record get locked even if the lookup field is not updated?

It's depends how you have configured the lookup field.

Record with a lookup relationship where Lookup record is locked

  • Insert new record with lookup value where Locks only occur: if lookup relationship is NOT configured to clear the value of this field if the lookup record is deleted.

  • Update record and change lookup value Locks only occur: if lookup relationship is NOT configured to clear the value of this field if the lookup record is deleted.

Same kind of principle applies to Rollup Summary field. Let's say Account has rollup summary taking from Opportunity. Even if, rollup summary value didn't change, the Account will be locked.

  • Thanks for the reply. I think I'm misunderstanding one of these examples: "1. If you are not updating AccountId in Case records then Salesforce will not lock the account record" "2. If you are updating Case with the same AccountId, then Account record got locked." how can these both be true? In the first one the account ID is not being updated, in the second one the account ID is not being updated (same AccountId). – bafuda Jan 24 '18 at 18:30
  • 1. lets say you are updating only Subject value. In the csv you have taken CaseId and Subject, then account will not get locked. It have updated point 1. – Santanu Boral Jan 24 '18 at 18:47
  • What does it mean to update "Case with the same AccountId"? Would that be something like case.AccountId = case.AccountId; update case; ? – bafuda Jan 24 '18 at 18:50
  • let's say in the csv you have mapped AccountId to update but you are not changing AccountId which exist in the case. basically case.AccountId = case.AccountId – Santanu Boral Jan 24 '18 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.