Find your content:

Search form

You are here

Customer portal user creation

 
Share

I am using following code for creating customer portal user

    u.FirstName = firstName;
    u.LastName = lastName;
    u.Username = email;
    u.Email = email;
    u.CommunityNickname = email;

Is it mandatory to pass CummunityNickname here? Actually my requirement is show only one field out of username and nickname.


Attribution to: doga

Possible Suggestion/Solution #1

When I remove the setting of the communitNickname field from the SiteRegisterController and from the SiteRegister page I get the following error when I submit the user form:

That nickname is invalid.

I think it is required that the field be set to a valid communityNickname. This question has some discussion on it. If you can limit the username to be no more than the length of the communityNickname then you should be able to set it to the userName. It's up to you, but generally I wouldn't force the email to be unique, because then that eliminates the possibility of someone having more than one account with the same email (e.g., I help my grandma shop and use my email for her account).

The link that Mohith referenced is useful if you are creating users for different accounts. If there is just one portal account then you don't need to implement that, but instead you can just use the Site.createPortalUser(user, accountId, password) method, where accountId is the Id of your portal account.


Attribution to: Peter Knolle

Possible Suggestion/Solution #2

The community nickname is a required field on the user object. It is used in Ideas, Answers, Articles (Knowledge) and a few other places.

According to the official documentation:

Community Nickname Name used to identify this user in a community. Up to 40 alphanumeric characters are allowed; standard users can edit this field.

Since you are building a Force.com Site and have complete control over the Visualforce markup and Apex code, you can decide not to display the community nickname to your users. However, to save the user record you will need a community nickname.

As some of the other answers have alluded to, you can generate your own community nickname behind the scenes.

In your example above, you might want to use the combination of first name and last name (although there are several other possibilities you could use).

u.FirstName = firstName;
u.LastName = lastName;
u.Username = email;
u.Email = email;
u.CommunityNickname = firstName + lastName;

Attribution to: Ryan Guest
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3498

My Block Status

My Block Content