We build a new napiliy commmunity site (Spring '17) and are using two profiles:
- Customer Community Plus and
- Customer Community Login
Users with the Community Plus profile should be able to create new "customer users".
The build-in UI for creating new customer users is still in the old vf-page style, so I am building a lightning custom component for creating and enabling customer users.
My code is working with my own user and admin profile, but with a "Customer Community Plus"-Profile-User i get this error:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Profile]: [Profile]
The User parameter comes from the ajax-call of my component and there IS a profileId supplied with the insert statement.
@AuraEnabled
public static boolean insertCustomerUser(User usr) {
System.debug(usr);
Profile p = [SELECT Id, Name FROM Profile where Name = 'Portal Profilename'];
User portalUser = new User(ProfileId=p.Id,
ContactId=usr.contactId,
Username=usr.Username,
Firstname=usr.FirstName,
Lastname=usr.LastName,
Email=usr.Email, Phone=usr.Phone,
CommunityNickName=usr.CommunityNickName,
Alias=usr.Alias,
Title=usr.Title,
TimeZoneSidKey=usr.TimeZoneSidKey,
LocaleSidKey=usr.LocaleSidKey,
EmailEncodingKey=usr.EmailEncodingKey,
LanguageLocaleKey=usr.LanguageLocaleKey);
System.debug(portalUser);
Database.SaveResult newPortalUser = Database.insert(portalUser);
return true;
}
Output of my first system.debug:
User:{[email protected], LocaleSidKey=de_DE, TimeZoneSidKey=Europe/Berlin, LanguageLocaleKey=en_US, FirstName=fn, Title=, ContactId=00358000005HMeMAAW, EmailEncodingKey=ISO-8859-1, CommunityNickname=NickName, Username=userEmailname, Phone=+49 (0)69, Alias=alias, LastName=ln}
output of my second debug and insert-statement:
User:{ProfileId=00e58000000cXDXAA2, ContactId=00358000005HMeMAAW, Username=userEmailname, FirstName=fn, LastName=Caicedo, [email protected], Phone=+49 (0)69, CommunityNickname=NickName, Alias=alias, Title=, TimeZoneSidKey=Europe/Berlin, LocaleSidKey=de_DE, EmailEncodingKey=ISO-8859-1, LanguageLocaleKey=en_US}
I think there must be some security option missing, because this code is working with my admin userprofile.