Activity Forums Salesforce® Discussions How to create a salesforce partner community user in test class?

  • Vikas Kumar

    January 23, 2017 at 10:19 am

    Hi Tanu,

    Below is the code for creating user in the test Method for the Partner Community

    Id p = [select id from profile where name='Partner Community User'].id;

    Account ac = new Account(name ='Grazitti') ;
    insert ac;

    Contact con = new Contact(LastName ='testCon',AccountId = ac.Id);
    insert con;

    User user = new User(alias = 'test123', email='[email protected]',
    emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
    localesidkey='en_US', profileid = p, country='United States',IsActive =true,
    ContactId = con.Id,
    timezonesidkey='America/Los_Angeles', username='[email protected]');

    insert user;
    system.runAs(user) {
    // statements to be executed by this test user.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos