How to Base URL in the apex code.
Step 1: Login into salesforce account.
Step 2: Open Developer console and paste below code and execute.
Code:
String baseUrl = System.URL.getSalesforceBaseUrl().toExternalForm();
System.debug('baseUrl*****' + baseUrl);