• Dinesh Amarthaluri
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
public with sharing class HelperContactTrigger 
{

public static List<Contact> sendEmail(List<Contact> Contacts)

{
List<User> lstUser = new List<User>();
Profile objProfile = [select Id from Profile where name = 'Customer Community User'];
for(Contact objCon : Contacts)
{
    if(objCon.AccountId!=NULL && objCon.Email!=NULL)
    {
        lstUser.add(new User(contactId=objCon.Id, username=objCon.Email, firstname=objCon.FirstName,
                    lastname=objCon.LastName, email=objCon.Email,communityNickname = objCon.LastName + '_MCL',
                    alias = string.valueof(objCon.FirstName.substring(0,1) + objCon.LastName.substring(0,1)), profileid = objProfile.Id, emailencodingkey='UTF-8',
                    languagelocalekey='en_US', localesidkey='en_US', timezonesidkey='America/Los_Angeles'));

    }
}    
HelperContactTrigger.createPortalUsers(JSON.serialize(lstUser));
return NULL;
}

@future
public static void createPortalUsers(String strUser)
{
   insert (List<User>)JSON.deserialize(strUser,List<User>.class);
}

}