automate creating communities user

匿名 (未验证) 提交于 2019-12-03 01:42:02

问题:

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.

回答1:

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; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!