0

I have written a trigger in Leads to convert the Leads from WEB-TO-LEAD to Contacts/Accounts. written a trigger to convert from contact to portal user. getting error Please anybody help me where i'm making mistake? Here is the code:

Apex Trigger

trigger allowCustomerPortal on Contact (after insert) {
    List<string> setcontact=new List<string>();
    system.debug('setcontact::'+setcontact);
    for(contact c:trigger.new){
        setcontact.add(c.id);
        system.debug('setcontact::'+setcontact);
    }

    List<contact> con=[select id,email,firstName,lastname,accountId from Contact where Id =:setcontact];     
    system.debug('con::'+con);
    Profile pf = [SELECT Id FROM profile WHERE name='It industry' limit 1];  
    system.debug('pf::'+pf);   
    List<User> u=new List<User>();

    for(Contact contact : con){
        User mockUser = new User(contactId=contact.Id, 
                                 IsActive = true,
                                 username=contact.Email, 
                                 firstname=contact.FirstName,
                                 lastname=contact.LastName, 
                                 email=contact.Email,
                                 communityNickname = contact.LastName ,
                                 profileid = pf.Id, 
                                 emailencodingkey='UTF-8',
                                 languagelocalekey='en_US', 
                                 localesidkey='en_US', 
                                 timezonesidkey='America/Los_Angeles');

        u.add(mockUser);
        system.debug('u::'+u);
    }
    insert u;
}
3

0

You must log in to answer this question.

Browse other questions tagged .