How to get salesforce base URL in Apex.

Published by

on

BASE URL

You can get that using System.URL class. You will find the complete documentation HERE.

Below code snippet will give you the base URL and then you can concatenate with record ID to make record detail page URL.

// Get the base URL.
String sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm();
System.debug('Base URL>>' + sfdcBaseURL );  

// Create the account URL from the base URL.
String accountURL = URL.getSalesforceBaseUrl().toExternalForm() + 
                       '/' + accountRec.Id;
System.debug('URL of a particular account>>' + accountURL);

You can also run above code in anonymous window to check the output.

no-ads-1

Did this post help you?

Help to make such content ads-free!

US$2.00