Creating a scratch org with the new DeferSharingCalc feature on doesn't change anything regarding sharing calculations:
{
...
"features": ["DeferSharingCalc"],
"settings": {
...
}
}
Is there anything else needed as a prerequisite for this?
(via https://salesforce.stackexchange.com/questions/268450)
@clairebianchi thanks for tagging. Should I move the issue to another Github repo?
No, I am reaching out to the Product Manager on that team to see how he wants to handle the issue. They do not have an open-source repo, so I don't want to close this till someone takes ownership of the internal bug
Hi @rsoesemann thanks for reporting the problem. Enabling the Defer Sharing Rule Calculation feature typically requires two steps - contacting Salesforce support and then enabling the feature in the UI (https://help.salesforce.com/articleView?id=security_sharing_rule_recalculation.htm&type=5). It appears that the scratch feature "DeferSharingRecalc" is helping with the first step but it requires the user to provision the appropriate permission and then Suspend, Resume or Recalculate sharing rules in the UI. This is definitely not automation-friendly and we need to do more work to make it so. I will open an enhancement request for the Sharing team, make sure our documentation is updated in the interim and also re-post this message in StackOverflow.
Thank you @rrmehta2, I am going to close this issue here and you can track it internally.
@rrmehta2 thanks so much. Feel free to add comments to my stack exchange answer later.
Now that this issue has been closed and that it's tracked internally, can we get some information on what we can expect ? Is it in the roadmap now, or just in the backlog ?
Obviously as soon as we have sharing rules, this break the automatic creation of a scratch org, with a manual step in the middle.
This is also an issue for continuous deployment on a sandbox.
As you can imagine, I have several customers having the issue. I'll be happy to ask them to comment here if you need some customer references to prioritize this.
@rrmehta2 can you give some roadmap guidance here?
Hi everyone, does we have any update regarding this issue? I cant see any way how to automate this manual step still.
@patrykacc For example, you could do the following:
sfdx force:mdapi:deploy --deploydir=deploy/deployDeferSharingCalc --wait=-1 where deploy/deployDeferSharingCalc contains a permission set DeferSharingCalc with DeferSharingCalculations=true sfdx force:org:display --json to get the current usernamesfdx force:user:permset:assign --permsetname DeferSharingCalc --onbehalfof username where username is the username from step 2@jayree thanks, but is this going to suspend sharing rules calculation, or just enable taht "Defer" option for my org? My main goal is to setup CI process using scratch org, and for now I see "best" option as using selenium as in middle step to suspend reclaculation before metadata deploy.
@patrykacc you're right, you need to solve this with e.g. selenium or puppeteer. I will contact you by e-mail with further information how I did this. I don't know if I'm allowed to share this here directly.
@patrykacc we have several commands to automate this through Puppeteer:
We started with the first one and @kylethornton came to the rescue to do the 2 other ones.
You still need to do the previous steps (add the feature to the scratch definition file + permission set), but then these commands will let you automate what can't be done out of the box via the Salesforce APIs.
@FabienTaillon > Thanks for the great tool :)
But I have an issue , it seems to not succeed to find the wait to suspend recalc in UI, it is still working in Spring 21?
...
"features": ["DeferSharingCalc"],
...

โ [sfdx-hardis][command] sfdx force:mdapi:deploy --deploydir D:\git\sfdx-hardis\defaults\utils\deferSharingCalc --wait 60 --testlevel NoTestRun --apiversion 51.0
[sfdx-hardis] Job ID | 0Af1X00001MHn5nSAD
โ [sfdx-hardis][command] sfdx force:user:permset:assign -n SfdxHardisDeferSharingRecalc -u nicolas.vuillamy@hardis-scratch-nvuillamy-deploy__sharing_2021-03-26_08-23.com --json
โ [sfdx-hardis][command] sfdx texei:sharingcalc:suspend
[sfdx-hardis] Suspending Sharing Rule Calculations... Done.
Unable to suspend sharing. No node found for selector: #ep > .pbBody > .pbSubsection > .detailList > tbody > .detailRow > td > input[name="rule_suspend"].btn
โ [sfdx-hardis][command] sfdx force:source:push -g -w 60 --forceoverwrite -u NVUILLAMY-deploy__sharing_2021-03-26_12-09
Job ID | 0Af1X00001MBUDqSAP
TYPE PROJECT PATH PROBLEM
โโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Error N/A sharing operation already in progress (3:24)
Or maybe it could be related to the fact that the scratch org is created in french ? ( not by choice ^^ )
The command could also return 1 and not 0 when there is a failure
@nvuillam can you please create an issue in our repo ? I'll have a look on Monday, I'm not working today :)
@FabienTaillon will do that, have a nice weekend :)
I may have a clue... the button is just not appearing on the page ๐๐
Maybe some more rights needed ?
@nvuillam are you defining the scratch org to have the DeferSharingCalc feature enabled?
your features array in your project-scratch-dev.json should include "DeferSharingCalc"
@FabienTaillon false alarm, it was an issue with my Permission set :)
To others needing the feature, you can use sfdx hardis:scratch:create (available in VsCode SFDX Hardis extension) , or manually deploy this metadata folder containing the appropriate PS :)
https://github.com/hardisgroupcom/sfdx-hardis/tree/main/defaults/utils/deferSharingCalc
Thanks again for sharing your command :)
@kylethornton thanks for the support, it's all good now :)
Most helpful comment
Now that this issue has been closed and that it's tracked internally, can we get some information on what we can expect ? Is it in the roadmap now, or just in the backlog ?
Obviously as soon as we have sharing rules, this break the automatic creation of a scratch org, with a manual step in the middle.
This is also an issue for continuous deployment on a sandbox.
As you can imagine, I have several customers having the issue. I'll be happy to ask them to comment here if you need some customer references to prioritize this.