+ Start a Discussion

Notify password to new customer portal user from Apex code



I'm writing apex code which automates creation of a customer portal user.

First I create a new contact. Then I create a new user linked to that contact, with all required attributes to access the customer portal. It all works well except that I can't get the new password notification sent to the new user.


In other words, I can't find a way to "select" the "Generate new password and notify user immediately" option from apex.


Any hint would be highly appreciated!!!





I'm looking for essentially the same thing!


OR any such workaround.


Have tried in APEX to create Account and Contact linked to said account and ticked the IsPortalSelfRegistered tickbox and created User Record linked to said contact but no luck.


Have tried to mimic HTTP Post to Customer Portal URL "new user signup form" and again no luck.


I get standard System.CalloutException: Callout from triggers are currently not supported error.


Really need some sort of solution here. 


You can 'SetPassword()' and 'resetPassword()' via the API but not via APEX??? seems a little odd.


I know there is a sites class coming with a createPortal user method but that's not general release yet and I need something now.


Anywho anyone with any insight whatsoever let me know I'll keep plugging away, with a few other ideas.

Message Edited by pblz on 03-22-2009 10:40 PM
Database.DMLOptions dlo = new Database.DMLOptions();

dlo.EmailHeader.triggerUserEmail = true;

This code might help when you create users via apex.


Is there any setting on Data Loader for this? I am trying to generate password for all the users I insert using Data Loader.

Let me know if there is any work around for this.


That is only setting the options, not applying it to your object.  You will need to use the setoptions method.


Database.DMLOptions dlo = newDatabase.DMLOptions();

dlo.EmailHeader.triggerUserEmail= true;



where u is a reference to my user object.