we have the following setup:
- Private sharing model on the Account object
- Sharing rule to share Account records with role and subordinates based on the Account record type field
The task
Update Account record after Lead conversion without additional async call using Apex (with sharing). Basically, two actions to do:
- Convert lead using Database.convertLead method
- Update a few fields in the new converted Account record
The problem
We have a lead record, where the owner is a different user. But it's under the same role. So, converted records are available to view/edit under the current user via Salesforce UI.
When we convert it in Apex, it's not possible to update the Account record. We could not query the new Account. Also, the "hard" update with setting account id doesn't work as well:
Update failed. First exception on row O with id 0012500001z7HUAAI; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insuffic ient access rights on cross-reference id: 0012500001zs7Hu
Our idea that is because Salesforce executes sharing rules almost at the last step based on the order of execution. But we are not 100% sure that the reason.
What do you think?