function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Venki123Venki123 

Urgent Help-Creating PartnerPortal User in Test Class having issue with IsPortalEnabled

Hi I need to write test class for partner portal users. The problem is i am not able to create partner portal user in test class

due the error IsportalEnabled is not writable.

 

User approverUser = new User(ProfileId = prof.id,LastName = 'Test', FirstName = 'Test', Username = 'testing456@test.com', Alias='test', CommunityNickname='test Approve', Email='test@email.com',TimeZoneSidKey='America/Chicago',EmailEncodingKey='ISO-8859-1', LanguageLocaleKey='en_US', LocaleSidKey='en_US',IsActive=false,IsPortalEnabled = true,Email_Address__c='test@email.com',EmployeeNumber='6534866',Legacy_Employee_Ref__c='487547');
Insert approverUser ;

 

I uderstand that this field is not writable.Can you please suggest how i can do the test class for this scnario. 

 

Thanks and Regards,

Venkatesh

Parth_SevakParth_Sevak

You may try  this,,,

 

Profile profile = [ select Id from Profile where Name=:profileName];
        
Contact contact = new Contact(AccountId = accountId, LastName = lastName);
 insert contact;
        
User user = new User(ContactId = contact.Id,
            Username = 'username',
            Email = 'username',
            LastName = 'lastName',
            Alias = 'alias',
            ProfileID = profile.Id,
            PortalRole = 'Manager',
            LocaleSidKey = 'en_US',
            LanguageLocaleKey = 'en_US',
            TimeZoneSidKey = 'America/Los_Angeles',
            EmailEncodingKey='UTF-8'
        );
        insert user;


        user.IsPortalEnabled = true;

        update user;


        return user;
    }