I am trying to create a scratch org. My codebase is having a class which is doing a dml on accountshare record. For deployment of this class we need to have account's OWD as private. (As well as of contact, case and opprotunity). So I made changes in Account Account.object-meta.xml. and made sharing model as private.

`<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">

Same for case, opportunity and contact. But still while deploying I am getting this error

DML operation Delete not allowed on List<AccountShare>

I can comment the dml operations and deploy it.

After first deployment subsequent deployments works fine even with AccounShare Code uncommented.

How we can fix this problem without having to do any manual work.


Sharing Settings changes take a non-zero amount of time to complete, and until they complete, the relevant Share object is not available.

If you're creating scratch orgs in a CI context, you'll need to implement a polling solution. Once you deploy your CustomObject metadata to the scratch org to enable sharing on those objects, have a script poll the Describe API until the required Share objects become available. Then proceed to deploy the remainder of your metadata.

If you're building one-off orgs, just wait a few minutes for the email that your sharing update is complete, or check in the org to see that it's finished, prior to performing your next deployment.


@David Reeds answer might be most accurate. But will take some time to implement. So I have a quick workaround.

First deploy only the objects using command

sfdx force:source:deploy -m CustomObject

After that you can deploy whole code.

you can create a .sh file like scratch.sh


sfdx force:source:deploy -m CustomObject 
sleep 30s
sfdx force:source:push

Then you can call ./scratch.sh

Above solution will work if your objects don't have dependency to other metadata like object translations and vfpages.

If that is the case then you can a file with commented code keep it in a folder lets say commentedcode and create other folder uncommentedCode.

Then lets create a scratch.sh


mv src/app/main/default/classes/abc.cls uncommentedCode/
sleep 4s
mv commentedcode/abc.cls src/app/main/default/classes/
sleep 4s
sfdx force:source:deploy 

mv src/app/main/default/classes/abc.cls commentedcode/
sleep 4s
mv uncommentedCode/abc.cls src/app/main/default/classes/
sleep 4s

sfdx force:source:deploy -p src/app/main/default/classes/abc.cls

Again run scratch.sh

So what I am doing is first deploying code with commented accountshare dml's and once all the deployment is done of account as private record is done then deploying uncommented code.

I will accept this answer as correct for now. If anyone else have more correct solution.. please write your answer I will be happy to make your answer as correct.

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.