Nov 7 · 1 min read

A client came to me mention a Visualforce page not working in Production, telling me it worked fine in Sandbox.
Issue
First look in the Visualforce page was enough to locate the issue, the WebToCase action was hardcoded in the html, like this :
action="https://llib--dev1.cs80.my.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8"So the cases were created in some old not even valid sandbox.
Solution
I replace the URL with some more dynamically formula:
** in some cases where myDomain contains hyphens you will need to change the formula
{!SUBSTITUTE(SUBSTITUTE($Site.Domain, "-", "--"), "force.com", "my.salesforce.com")}So now the action attribute look like this :
action=”https://{!SUBSTITUTE(SUBSTITUTE($Site.Domain, “-”, “ — “), “force.com”, “my.salesforce.com”)}/servlet/servlet.WebToCase?encoding=UTF-8"Testing..
and it’s working :)
