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
Gigi.OchoaGigi.Ochoa 

Site.CreatePortalUser() returns NULL sometimes

Hi, I have some code that creates Community Users using SIte.CreatePortalUser().  I create a contact or find an existing contact, and the User selects an Account (for a Drop Down List).  When I run Site.CreatePortalUser(user, accountId, password) usually it works, but sometimes it returns NULL.  

I have tried troubleshooting why it return NULL, but cannot find anything.  I am using forceSSL=true on the VF page, I ensure the Username (email) does not already exist in the User table, I've ensure the Account is owned by someone with a Role, I've ensure that if I find an existing contact it is not already associated to a Community User, and all required fields on the User are filled.  

Am I missing anything else?

Also, I read somewhere that if Site.CreatePortalUser() does not work, it is suppose to send an email to the Site Administrator.  I have yet to see that email.

Any suggestions would be greatly appreciated.

 
EnreecoEnreeco
Ansure you have a apex:pageMessages tag in your page: the code automatically adds a page message to your page stating the actual errore (it could be anything from duplcates, to user already created on that contact, ...).
So if the method returns null, simply return to your page leaving salesforce displaying the page message.
Hope this helps
--
May the Force.com be with you!
EalesieEalesie
Gigi,

Have you had any success yet  ?

- I am seeing the same behaviour yet the user is created as I can SOQL out afterwards.   I am then trying to login as the user that has just been created via the Site.Login method and this fails.

Thanks
Ealesie