Activity Forums Salesforce® Discussions How to assign portal user in test class?

  • Himanshu

    Member
    July 28, 2016 at 7:51 am

    Hi Pranav,Use the below code to assign portal user in test class.

    ID ProfileID = [ Select id from Profile where name = 'Customer Portal Manager Custom'].id;

    Account acc = new Account(Name = 'Test Account');

    insert acc ;

    List<Contact> ContactList = new List<Contact>();

    Contact Con = new Contact( AccountID = acc .id, FirstName = 'User', LastName = 'test',

    email = '[email protected]' );

    insert Con;

    User u = new User( email='[email protected]', contactid = Con.id, profileid = profileid, UserName='[email protected]', alias='tuser', CommunityNickName='tuser',

    TimeZoneSidKey='America/New_York', LocaleSidKey='en_US', EmailEncodingKey='ISO-8859-1',

    LanguageLocaleKey='en_US', FirstName = 'User', LastName = 'Test' );

    insert u;

    Hope this helps you.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos