+ Start a Discussion

Get customer portal url dynamically in apex class



I have a webservice class in which i am consturcting url for customer portal users. I've hard coded the customer portal url all these days and now i want to make it dynamic so that i need not make changes to the class when ever i refresh my sandbox with sandbox portal urls. This is what the url looks like now,



 What i want is, i need to know how to get the portal url, org id and portal id dynamically in my apex class and construct a url of above format.


Any methods/ pointers/ code snippets are appreciated.








UserInfo.getOrganizationId you can try this one for org id or


put both of those id's in a custom settings and use them in your class, you can change them based on the environment.


I dont want any maintenance to be done by admins.


With custom settings, anyways admins need to change it for each sanbox refresh. So i wouldnt want to take this route.


Any other solutions?