This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: apex-security/hardcoded-salesforce-url

Language: Apex

Severity: Notice

Category: Security

Description

Using absolute URLs to reference Salesforce pages introduces fragility, as sandbox and production environments are assigned different instance names. Code written with absolute URLs will only function within the corresponding Salesforce instance and will fail once deployed elsewhere. To ensure portability and reliability, always use relative URLs—omitting both domain and subdomain—when linking to Salesforce pages.

Non-Compliant Code Examples

public class AccountHelper {
    
    // A method inside the class
    public List<Account> getActiveAccounts(Integer limitSize) {
        String foo = 'https://subdomain.salesforce.com/something';
    }
}

Compliant Code Examples

public class AccountHelper {
    
    // A method inside the class
    public List<Account> getActiveAccounts(Integer limitSize) {
        String foo = URL.getSalesforceBaseUrl().toExternalForm() + '/something';
    }
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains