function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gautam_KasukhelaGautam_Kasukhela 

Access Community Custom URL in Apex

Hey All,
     How can I access a custom URL defined for a community in Apex? 
     I am getting the base URL in Apex by using 
Network.getLoginUrl(communityId)
but this does not give me the custom URL, it gives me the base Url.
e.g my community base url : 
https://abc.force.com/community1
but my Custom URL configured (Setup> Custom URL) for this community is https://www.community1.com

and I want to read the custom URL value in Apex. Any pointers?

Regards,
Gautam.
 
Best Answer chosen by Gautam_Kasukhela
Gautam_KasukhelaGautam_Kasukhela
Got the answer, it s a combination of Domain & DomainSite objects.

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Gautam,
Greetings!

You can get a Community URL by SOQL Query in Network.
Please replace CommunityName with your community name.
SELECT Name,UrlPathPrefix FROM Network WHERE Name ='CommunityName' 

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
Gautam_KasukhelaGautam_Kasukhela
hey Suraj,
     That SOQL does not give me the custom URL, it only gives me 'community1' . I simplified the Custom URL for easy understanding but actually it has no resemblance with the salesforce generated community URL.
In my case , if salesforce generated URL is  https://abc.force.com/community1 then custom URL is https://www.goforitadmin.com
and I want the custom URL in apex.
 
Gautam_KasukhelaGautam_Kasukhela
Got the answer, it s a combination of Domain & DomainSite objects.
This was selected as the best answer