Our sandbox is refreshed often. To re-create the portal environment on the sandbox entails number of manual steps.

I have a seven test accounts and each account has exactly one contact. Recreating this data is easily scripted after a sandbox refresh.

I would now like to automate the enabling of each of these seven accounts as a partner community and the associated contact for each account as a community user.

Is there an api to automate some or part of this? Is this even possible?

  • 1
    It's not an area I've worked in too much, but is this automation of Manage External User->Enable Customer User on the Contact record? – Phil Hawthorn Jul 1 '15 at 16:55
  • @PhilHawthorn I think, automating Manage External Account > Enable As Partner on the Account record... – bigassforce Jul 2 '15 at 8:47
  • I'm out then....definitely not something i've worked with – Phil Hawthorn Jul 2 '15 at 14:31

To enable the accounts as partner accounts, set the 'IsPartner' field to true after creating the account (it cannot be done during creation, only by update).

Account partnerAccount= new Account(
    Name = 'theAccount',

partnerAccount.IsPartner = true;
update partnerAccount;

Next step is to add the contacts/users. I think the only known way is to just create a Contact under the partner account, then create a User (with the right partner profile) and link the user to the contact by filling the ContactId field.

//Create contact
Contact theContact = new Contact(
    FirstName = 'Test',
    Lastname = 'Contact',
    AccountId = partnerAccount.Id,
    Email = 'test@test.com'


//Create user
Profile portalProfile = [select Id from Profile where UserType = 'PowerPartner' limit 1];

User theUser = new User(
    Username = 'test123@test.com',
    ContactId = theContact.Id,
    ProfileId = portalProfile.Id,
    Alias = 'test123',
    Email = 'test123@test.com',
    EmailEncodingKey = 'UTF-8',
    LastName = 'McTesty',
    CommunityNickname = 'test123',
    TimeZoneSidKey = 'America/Los_Angeles',
    LocaleSidKey = 'en_US',
    LanguageLocaleKey = 'en_US'
| improve this answer | |
  • I just did similar using a Flow and it works well. I thought I would have to resort to code, but everything works nicely (and no, this client will not be creating bulk partner users). – JodieM Oct 5 '17 at 2:54
  • @JodieM that's good to know, tnx! – Guy Clairbois Oct 5 '17 at 12:07

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.