If you are looking to associate to a single record, you will need to use the PageReference class. Specifically:
ApexPages.currentPage().getHeaders().get('Host');
and
ApexPages.currentPage().getHeaders().getUrl();
To piece that together you would use the following:
String url = 'https://' + ApexPages.currentPage().getHeaders().get('Host') + ApexPages.currentPage().getHeaders().getUrl();
If you are looking to link to a specific object, you just need the host and the ID of that object. Say you want to link to an account for instance and the account you have is referenced by the acc variable:
String url = 'https://' + ApexPages.currentPage().getHeaders().get('Host') + '/' + acc.Id;
select NamespacePrefix, Name from ApexPage limit 10? – eyescream Jan 24 at 17:29[SELECT Name, Status, Subdomain FROM Site]this only gives me the subdomain in subdomain.force.com, this should work well when installed on a production org, but when using the app on a dev org / sandbox you get a different URL for example:http://subdomain.na14.force.com/sitename– PJC Jan 24 at 17:35