Have you ever created a new scratch org with sfdx but seem to have trouble access visualforce pages? This seems to be a know issue and can take 0-18 minutes before the org is fully operational. This random delay can cause havoc on e2e/integration testing as well as unit test. So after many attempts to fix or delay CI/CD I believe I have finally found a solution.
First let's talk about the actual issue, spinning up a new scratch org. After running sfdx force:org:create
you will receive a success
message along with login/password info for your org. The core sfdc features of the org are almost ready instantly but if you have a
managed package with namespace it takes 0-18 minutes. Navigating to one of these pages(vf pages) will not error with a 404 nor will they timeout.
However it will load a blank screen so let's dig in a bit 😺
The domain name of your org is stored inside .sfdx/org
and using get-visualforce-url.js
will return the visualforce domain name for this org.
Now running the dig command on this url should return something like cs66-iad.iad.r.force.com
. Unfortunately during the 0-18 minute delay dig
will return location.l.force.com
. This means the data center your org is running on is not 100% ready.
So how do we fix this? Simple just add a step to local or CI/CD to run dig every 30 seconds until your scratch reports the correct data center.