Pregunta

Would it be possible to automate the process of creating a communities user in Salesforce? I was thinking of a trigger on the contact that would then create the user record with the communities license. Would this be possible at all?

Thanks.

¿Fue útil?

Solución

Yes it should be something like this

Contact con = [select id,email,firstName,lastname,accountId from Contact where Id =:contactId];         

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.EmailHeader.triggerUserEmail = false;       
dmo.EmailHeader.triggerOtherEmail = false;
dmo.EmailHeader.triggerAutoResponseEmail = false;       
dmo.optAllOrNone = false;

// create portal user
string nick = con.email!=null?con.email.substring(0, con.email.indexOf('@')):'';
nick += Datetime.now().getTime();
User newUser = new User(
                    alias = createAlias(con.firstName, con.lastName), 
                    email = con.email, 
                    emailencodingkey = 'UTF-8', 
                    firstname = con.firstName, 
                    lastname = con.lastname, 
                    languagelocalekey = 'en_US', 
                    localesidkey = 'en_US', 
                    contactId = con.Id,
                    timezonesidkey = 'Asia/Dubai', 
                    username = con.email,
                    CommunityNickname = nick,
                    ProfileId = .......,
                    IsActive = true);

newUser.setOptions(dmo);
insert newUser;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top