How to get Base URL in Salesforce from managed package context?

I have modified an answer which I have found here.


public class URLService {
@auraEnabled
public static String getBaseURL() {
PageReference pr = new PageReference('/id/' + UserInfo.getOrganizationId() + '/' + UserInfo.getUserId() + '?oauth_token=' + UserInfo.getSessionId() );
System.debug(LoggingLevel.ERROR, '@@@ v: ' + pr.getContent().toString() );
String data = pr.getContent().toString();
Map result = (Map)Json.deserializeUntyped(data);
Map urls = (Map)result.get('urls');
System.debug(LoggingLevel.ERROR, '@@@ v: ' + (String)urls.get('rest') );
String rest = (String)urls.get('rest');
String[] items = rest.split('/');
return items[0] + '//' + items[2] + '/';
}
}

This entry was posted in salesforce and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s