I'm getting ready to do a large-scale Customer Portal implementation that will involve 1000+ CP user accounts. These will typically be added in batches of 40-60 users at a time, usually associated with a single account.

From my initial research, it looks like the only way to create CP accounts is one-by-one through the individual's Contact page, but that they can also be administered via Apex and the APIs. Are there any existing AppExchange or other tools to allow provision/closing of CP accounts in bulk?


I'm not aware of an App Exchange App for it, but someone else might be.

You should be able to use the Data Loader, but the only catch would be that the new user email notification would not go out.

If you use Apex from a custom page, batch job, or just execute anonymous you have to set the DMLOptions to send email if you want email to be sent, for example:

List<Contact> portalContacts = [
     Select Id, ...
     From Contact
     Where ...

Id portalProfileId = '123456789012345678';

Boolean sendUserEmail = true;
Boolean allOrNone = true;

List<User> newUsers = new List<User>();

for (Contact contact : portalContacts) {
    String alias = contact.LastName;
    if (alias.length() > 8) {
        alias = alias.substring(0, 8);
    String nickName = contact.Email;
    if (nickName.length() > 40) {
        nickName = nickName.substring(0, 40);

    User newUser = new User(
            UserName = contact.Email,
            LastName = contact.LastName,
            FirstName = contact.FirstName,
            Email = contact.Email,
            phone = contact.Phone,
            MobilePhone = contact.MobilePhone,
            Street = contact.MailingStreet,
            City = contact.MailingCity,
            State = contact.MailingState,
            Country = contact.MailingCountry,
            PostalCode = contact.MailingPostalCode,
            CommunityNickName = nickName,
            Alias = alias,

            /* link to the contact and to the account through the contact... */
            ContactId = contact.Id,

            ProfileId = portalProfileId,

            /* various user settings */
            emailencodingkey = 'UTF-8',
            languagelocalekey = 'en_US',
            localesidkey = 'en_US',
            timezonesidkey = 'America/Los_Angeles'

    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.EmailHeader.triggerUserEmail = sendUserEmail;


if (!newUsers.isEmpty()) {
    Database.SaveResult[] results = Database.insert(newUsers, allOrNone);
    // any post processing...
  • This is a great snippet! I'm going to wait to accept in case anyone recommends existing tools, but could definitely see building something around this. – Benj Aug 9 '12 at 14:08
  • @Benj - It's been a few days. Can you please accept this if you feel comfortable nobody else is going to recommend something? Thanks! – Peter Knolle Aug 11 '12 at 15:42

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.