I am trying to insert a partner community user in my test class. I have created a contact and associated it to the new user but I'm getting the error : "Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Invalid role assignment.: []"
accList = new list<Account>{
new Account(Name = 'CourtierPrincipal', Num_ro_ORIAS__c='12345', RecordTypeId = recordTypeMap.get(AP_Constants.rtAccCompte_Tiers_courtier))
};
insert accList;
contactList = new list<Contact>{
new Contact(LastName = 'CourtierPrincipal', AccountId = accList[0].Id, RecordTypeId = recordTypeMap.get(AP_constants.rtConContact_Business_courtier))
};
insert contactList;
for(UserRole role:[select Id, DeveloperName from UserRole]){
roleMap.put(role.DeveloperName, role.Id);
}
courtierPrincipal = new User(
alias = 'testUsr2'
,email='testUser2@noemail.com'
,emailencodingkey='UTF-8'
,lastname='testUser2'
,languagelocalekey='fr'
,localesidkey='fr_FR_EURO'
,profileid = profileMap.get('Principal')
,timezonesidkey='Europe/Paris'
,username=getUserNamePrefix() + 'standarduser2@testorg.com'
,ContactId = contactList[0].Id
,UserRoleId = roleMap.get('PartenaireResponsable')
);
insert courtierPrincipal;