You need to sign in to do that
Don't have an account?
Ryan Thomas 317
parse domain from url with apex
We have a Sites page with a form with one question asking for the applicant's website url.
Instead of accepting the website provided, we are trying to pull out the domain from the provided url. So if someone types in http://www.test.com/ or https://www.test.com/ or www.test.com/test1234, we'd want to use apex to insert the domain only (test.com). Can anyone help?
Instead of accepting the website provided, we are trying to pull out the domain from the provided url. So if someone types in http://www.test.com/ or https://www.test.com/ or www.test.com/test1234, we'd want to use apex to insert the domain only (test.com). Can anyone help?
All Answers
String url = urlToParse+'/'; // to handle https://developer.salesforce.com url
String domain = url.substringBetween('://', '/');
System.debug(domain)
// developer.salesforce.com