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
ChitraChitra 

Creating portal user using API

I am having issues creating customer portal user using the API. Following is the sample code snippet.

Contact cc = new Contact();
    cc.FirstName = ' test';
    cc.LastName='dd';
    List <Contact> insertCon = new List<Contact> ();
    insertCon.add(cc);
    insert insertCon;
    
    User insertUser = new User();
    insertUser.Username='dddd@test.com';
    insertUser.LastName='Name';
    insertUser.Email='ddd@test.com';
    insertUser.Alias='dddd';
    insertUser.TimeZoneSidKey='America/Los_Angeles';
    insertUser.LocaleSidKey='en_US';
    insertUser.EmailEncodingKey='UTF-8';
    insertUser.ProfileId='00eT0000000e5yN';
    insertUser.LanguageLocaleKey='en_US';
    insertUser.UserRoleId='00ET0000000muU0';
    insertUser.ContactId=cc.Id;
    insertUser.isActive=true;
    List <User> insertUsers = new List<User> ();
    
    insertUsers.add(insertUser);
    
    insert insertUsers;


I am getting the following error:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Invalid role assignment.


The values for profile and role IDs are from an existing customer portal user. This being the case, I am not sure why the error log indicates that there is an issue with the role assignment. If it is an issue, I don't know how to determine the correct profile and role when creating the user. Should I be looking for a specific type of role or profile?

Any help is appreciated.

Thanks,
Chitra



Scott JorgensenScott Jorgensen
Did you find a solution?  I just hit the exact same situation.
ChitraChitra
API version - Try 12.0

That is all I changed and also set the new portal users to a default  portal profile.

- CN

rashrash
Hi,

Could you pls lemme know how were you able to solve this issue, I am facing the same when I try to create a User via API, there is a problem in updating the Role in User Object.

Thx In advance.


ChitraChitra
Customize your portal to create default portal users .


In Set up> App Set up > Portal > Setting

Default New User RoleUser
Default New User ProfileCustomer Portal User

So in the code you dont have to set the role.

Regards,
Chitra
rajjjjrajjjj
I am getting the same Exception................

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Invalid role assignment.

Anybody resolved this!!!