URL Class
Represents a uniform resource locator (URL) and provides access to parts of the URL. Enables access to the base URL used to access your Salesforce org.
getOrgDomainUrl()
For example, https://MyDomainName.my.salesforce.com.
String orgDomainUrl=System.URL.getOrgDomainUrl().toExternalForm();
System.debug(orgDomainUrl);
getSalesforceBaseUrl()
For example, https://MyDomainName.my.salesforce.com or
https://MyDomainName.lightning.force.com
String baseUrlSalesforce=System.URL.getSalesforceBaseUrl().toExternalForm();
System.debug(baseUrlSalesforce);
The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base URL with the record ID.
Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
String fullRecordURL = System.URL.getSalesforceBaseUrl().toExternalForm() + '/' + acct.Id;
getCurrentRequestUrl()
An example of a URL for an entire request is
https://yourInstance.salesforce.com/apex/myVfPage.apexp
String currentUrlSalesforce=System.URL.getCurrentRequestUrl().toExternalForm();
System.debug(currentUrlSalesforce);
// Get the query string of the current request.
System.debug('Query: ' + System.URL.getCurrentRequestUrl().getQuery());
No comments:
Post a Comment