function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

User not recieving new user email with login credentials when created through apex.

This functionality is working for a very long time and it stopped recently not sure why.


we have to create a user through apex and grant them customer portal access and they should be recieving a welcome email with their login credentials.


Please take a look at our existing code. Its' giving them the portal access but not sending the email,

 User portalUser = new User();
            portalUser.Alias = con.Name.substring(0,2)+ultility_GlobalFunctions.generateRandomString(3);
            portalUser.Username = con.Email;
            portalUser.FirstName = con.FirstName;
            portalUser.LastName =  con.LastName;
            portaluser.CommunityNickname = con.Name.substring(0,2)+ultility_GlobalFunctions.generateRandomString(5);            
            portalUser.Email = con.Email;
            portalUser.Cost_Center__c = 'None';
            portalUser.Country = 'USA';
            portalUser.Region__c = 'AMER';
            portalUser.ContactId = con.Id;
            portalUser.ProfileId = [select Id from profile where Name= 'Manager'].Id;
            //portalUser.UserRoleId = [select Id from UserRole where Name = :recordtype].Id;        
            Database.DMLOptions dlo = new Database.DMLOptions();
            dlo.EmailHeader.triggerUserEmail = true;
            dlo.EmailHeader.triggerAutoResponseEmail= true;
                insert portalUser;     
            }catch( exception ed){              

 Please help...

if you're testing this in a sandbox or dev edition have you gone in and turned on the email sending?