Inspecting the self registration code added when Communities are turned on in a dev org, it appears that when a user self-registers a different API call should be used to setup the User (compared to older portal code). I have an existing self-registration page that I would like to work in both setups. Is there a reliable way to programmatically detect in Apex that the page is running inside a Community and so make the correct call? That is, what code could replace the ??? here:

Boolean isCommunity = ???;
Id userId = isCommunity
        ? Site.createExternalUser(u, c.accountId, null, true)
        : Site.createPortalUser(u, c.AccountId, null, true);
  • did you check the Site class? It has methods which run in community context Site.BaseURL() OR Site.getType()? – RedDevil May 30 '17 at 14:59
  • @RedDevil Yep Site.getType() returns "ChatterNetwork" which is consistent with the site documentation. If you add this as an answer I'll accept it. – Keith C May 30 '17 at 16:40

Please check site class it has method gettype which can give you the context from which you are running the code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.