I am a newbie to salesforce. I am stuck in a Community self registration page. While i am customizing a SelfRegistration page its showing an error-

That operation is only allowed from within an active site.

When i registering a user from inside the org it is running, but when i m trying to creating a user outside it raises an error.I have gone through the docs of community also but nothing is happening. Can anybody please help me out.

public with sharing class CommunitiesSelfRegController {

    public String firstName {get; set;}
    public String lastName {get; set;}
    public String email {get; set;}
    public String password {get; set {password = value == null ? value : value.trim(); } }
    public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
    public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }

    public CommunitiesSelfRegController() {}

    private boolean isValidPassword() {
        return password == confirmPassword;

    public PageReference registerUser() {

           // it's okay if password is null - we'll send the user a random password in that case
        if (!isValidPassword()) {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
            return null;

       // String profileId = ''; // To be filled in by customer.
        String roleEnum = 'Partner user'; // To be filled in by customer.
        String accountId = '00590000003g9SJ'; // To be filled in by customer.

        String userName = email;

        User u = new User();
        u.Username = userName;
        u.Email = email;
        u.FirstName = firstName;
        u.LastName = lastName;
        u.CommunityNickname = communityNickname;
      // u.ProfileId = profileId;

        String userId = Site.createPortalUser(u, accountId, password);

        if (userId != null) { 
            if (password != null && password.length() > 1) {
                return Site.login(userName, password, ApexPages.currentPage().getParameters().get('startURL'));
            else {
                PageReference page = System.Page.CommunitiesSelfRegConfirm;
                return page;
        return null;
  • Is your site active? can you share your code – Mohith Shrivastava Jan 2 '15 at 11:52
  • @MohithShrivastava yup my site is active. – RanVijay Jan 2 '15 at 13:21

This error comes - if we try to execute a method which is specific to Sites as 'internal user'. If you try it from the site page, you wont receive this error.

These specific methods are supposed to be used from sites alone. Ex : site.createPortalUser()

Thus, you are trying an operation which is intended to work only from Site page.


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.