Using absolute URLs to Salesforce Pages is bug prone. Different sandboxes and production environments will have different instance names (like "na10", "na15" etc.). Code using absolute URLs will only work when it runs in the corresponding salesforce instances. It will break as soon as it is deployed in another one. Thus only relative URLs, i.e. without the domain and subdomain names, should be used when pointing to a salesforce page.


This rule raises an issue when a string matches the regular expression:

{noformat}

(?<!\w)(login|test|(dns|test|[a-z]{1,2})\d{plus}{plus})\.(salesforce|force|visual\.force|content\.force)\.com(?!\w)

{noformat}


== Noncompliant Code Example

[source,apex]
----
public PageReference testRedirect() {
    String strUrl ='https://na8.salesforce.com/TestVFPage?AcoountId=999'; // Noncompliant
    PageReference newUrl = new PageReference(strUrl);
    newURL.setRedirect(true);
    return newURL;
}
----


== Compliant Solution

[source,apex]
----
public PageReference testRedirect() {
    String strUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/TestVFPage?AcoountId=999';
    PageReference newUrl = new PageReference(strUrl);
    newURL.setRedirect(true);
    return newURL;
}
OR
public PageReference testRedirect() {
    String strUrl = URL.getOrgDomainUrl().toExternalForm() + '/TestVFPage?AcoountId=999';
    PageReference newUrl = new PageReference(strUrl);
    newURL.setRedirect(true);
    return newURL;
}
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::message.adoc[]

include::highlighting.adoc[]

'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
