Skip to main content

Code reviews rule: Use of deprecated instance URL

Written by David Martin
Updated yesterday

Use of deprecated instance URL

Why is this an issue?

Instance URLs (like na1.salesforce.com) are not stable because your org could be migrated from one instance to another. Hardcoded instance URLs will break when that happens and must be manually updated.

Examples

Example of incorrect code:

String endpoint = 'https://na1.salesforce.com/services/data/v58.0/sobjects';
<url>https://na1.salesforce.com</url>

Example of correct code:

String endpoint = URL.getOrgDomainUrl().toExternalForm() + '/services/data/v58.0/sobjects';
<url>https://mycompany.my.salesforce.com</url>

How can I fix violations?

  1. Replace hardcoded instance URLs in Apex with URL.getOrgDomainUrl() to resolve the URL dynamically.

  2. Replace hardcoded instance URLs in metadata with your org's My Domain URL.

Resources

Did this answer your question?