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
NicoUruguayNicoUruguay 

Generate new password and notify user immediately

Hi:

 

I'm working in a Visual Force page that will override the Self-Service User Edit page. In Salesforce standard page, exist a checkbox: "Generate new password and notify user immediately".

 

 I need to replicate this functionality in my custom controller. Is there apex "out of the box" functionality or should I code it? Is that possible? 

 

Thanks,

nico. 

Best Answer chosen by Admin (Salesforce Developers) 
NicoUruguayNicoUruguay

Thanks!!

 

One possible solution could be accesing Salesforce via Api??

 

Thank you, 

nico. 

All Answers

aalbertaalbert

Are you creating a new user record in your controller? To send the email, you need to set the DMLOption

 

There is an example here

NicoUruguayNicoUruguay

Hi.

I need to create or update a SelfServiceUser in my controller. When I compile, for example, this code:

 

public with sharing class SelfServiceCreation {@futurepublic static void Create(){ List<SelfServiceUser> l = [Select Username, Name, Id, FirstName, Email, ContactId From

SelfServiceUser WHERE Email = 'oneEmail@gmail.com']; if (l.size() > 0){

l[0].Username = 'NewUserName'; update l;  

}}}

 The system return this error: DML not allowed on SelfServiceUser.

 

 Any idea? Thanks, 

nico. 

 

aalbertaalbert
Correct, DML is not allowed on that object as stated here
NicoUruguayNicoUruguay

Thanks!!

 

One possible solution could be accesing Salesforce via Api??

 

Thank you, 

nico. 

This was selected as the best answer
praveen murugesanpraveen murugesan
For me its worked

Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
dmlo.EmailHeader.triggerAutoResponseEmail= true;
user.setOptions(dmlo);
insert user;
mukkesh reddy 4mukkesh reddy 4

this is working fine... the above code missed a line...


Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
dmlo.EmailHeader.triggerAutoResponseEmail= true;
dmlo.EmailHeader.triggerOtherEmail = true;
user.setOptions(dmlo);
insert user;