Create a dynamic record URL using base URL method. Some time, we need to create record and redirect to that record details page. so here is the sample code for that using base url method of salesforce.
Answer
Account myAccount = new Account(Name='Acme');
Insert myAccount;
String accountURL = URL.getSalesforceBaseUrl().toExternalForm() +'/' + myAccount.Id;
System.debug('URL of a Acme account: ' + accountURL);