URL Class #inSalesforce
Enables access to the base URL used to access your Salesforce org.
Example:
To retrieve the base URL and the full request URL of the current Salesforce server instance. Then a URL pointing to a specific account object is created. Get components of the base and full URL.
// Insert Account named URLTRIALACCOUNT
Account myAccount = new Account(Name='URLTRIALACCOUNT');
insert myAccount;
// Get base URL.
String sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm();
System.debug('Base URL:::::::::: ' + sfdcBaseURL );
// Get URL for the current request.
String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
System.debug('Current request URL:::::::::: ' + currentRequestURL);
// Create account URL from the base URL.
String accountURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + myAccount.Id;
System.debug('URL of a particular account:::::::::: ' + accountURL);
// Get parts of the base URL
System.debug('Host:::::::::: ' + URL.getSalesforceBaseUrl().getHost());
System.debug('Protocol:::::::::: ' + URL.getSalesforceBaseUrl().getProtocol());
// Get the query string of the current request.
System.debug('Query:::::::::: ' + URL.getCurrentRequestUrl().getQuery());
Account myAccount = new Account(Name='URLTRIALACCOUNT');
insert myAccount;
// Get base URL.
String sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm();
System.debug('Base URL:::::::::: ' + sfdcBaseURL );
// Get URL for the current request.
String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
System.debug('Current request URL:::::::::: ' + currentRequestURL);
// Create account URL from the base URL.
String accountURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + myAccount.Id;
System.debug('URL of a particular account:::::::::: ' + accountURL);
// Get parts of the base URL
System.debug('Host:::::::::: ' + URL.getSalesforceBaseUrl().getHost());
System.debug('Protocol:::::::::: ' + URL.getSalesforceBaseUrl().getProtocol());
// Get the query string of the current request.
System.debug('Query:::::::::: ' + URL.getCurrentRequestUrl().getQuery());
Reference: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm
Comments
Post a Comment