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
MoggyMoggy 

enable / activate community via apex

HI All,

is there a way to activate a community via apex code.

The requirement is after a sandbox refresh, we run a class which creates all data needed for succesful testing , only bit left is the activation of the community , it would be nice to remove the needed admin step to login and activate the community, as contact, user and account are all there, its just the community is not active

Anyone has anything to share which works?

I know the workaround is to log in and do the setup bit, but i like to remove this administration step

ANUTEJANUTEJ (Salesforce Developers) 
Hi Moggy,

I have searched for this possibility but I was not able to find such way, so I don't think there is a possibility of activating the community from apex code the only possibility is to follow the administration step, and if you think this can be useful to others in the future then you can raise a new idea that can be upvoted by others in the future so that if it reaches the necessary threshold then it may be considered in the future.

I will check further but till now I have not found any such possibility and I will update with help articles in case if I find any.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
RituSharmaRituSharma
APEX is not meant for this. You may do it using metadata API. Refer below URL for details:

https://help.salesforce.com/articleView?id=networks_migrating_from_sandbox.htm&type=0