Wednesday, 13 May 2015

How to get salesforce instance url in apex class?

This is quite simple to get but some developer used to hard code that instance url, Actually we should not hard code url like "https://cs12.salesforce.com" because it differs from org to org.

Use below code to get instance url in apex class dynamically.

String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();

No comments: