2

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);
2
  • did you check the Site class? It has methods which run in community context Site.BaseURL() OR Site.getType()?
    – RedDevil
    Commented May 30, 2017 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
    Commented May 30, 2017 at 16:40

1 Answer 1

3

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

Site.getType();

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .