Salesforce Fact #915 | Issue with criteria based sharing rule in before trigger

Do you know criteria based sharing rules work asynchronously, hence they don't work as expected in before insert triggers.

In this example, we have two object Account(Parent) and Agent(Child) and there is lookup relationship present. Now, we have created a criteria based sharing rule on account such that it is in effect when the account number is 1234.

While creating an agent record we are creating an account record and setting the account owner explicitly to test out the sharing rule. We encounter an error while creating a new agent record and the account lookup is populated with some value.

However, it works fine with owner based sharing rules.

Reference: https://salesforce.stackexchange.com/questions/375247/when-does-sharing-rule-execute

Attached are the screenshots.

Note: The trigger code and sharing rules are only for demonstration purpose.








Comments

Popular posts from this blog

Salesforce Fact #192 | Call batch apex from flow