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
Virtuoso123Virtuoso123 

Generate a Self Service user's Password automatically

I'm fairly new to Apex Development. Our organization has a requirement to insert Contacts into the system and on insert or on update to the contacts, a Predefined password needs to be set for the Contact to be able to login to Self Service Portal. I was wondering if this is possible at all?

Shashikant SharmaShashikant Sharma

You can use 

 

1)FIrst you hae to create a portal user for this contact, just create a user with insert statement, only thing is set contactid of user to contact for you want to create user, and profileid should be your service portal profile id .

 

 

 

Then you can use 

 

system.setPassword(userID , PasswordString) method

 

Sets the password for the specified user.When the user logs in with this password,ID userID VoidString passwordsetPasswordthey are not prompted to create a newpassword.

 

 

Let me know if any issues in it.

 

 

Virtuoso123Virtuoso123

Thanks Shashikant.

I tried to insert a portal user using insert statement, but got an error:

 

DML not allowed on SelfServiceUser

 

Could u guide me please?

Shashikant SharmaShashikant Sharma

Are you doing it in constructor? Could you please share the code?

Virtuoso123Virtuoso123

I'm doing it with a trigger:

 

Map<id,SelfServiceUser> ssu = new Map<id,SelfServiceUser>([Select id, name,contactid, username from SelfServiceUser]);
   for(Contact c : trigger.new){
       if(ssu.containsKey(c.id)){
       ssu.get(c.id).username = c.ID__c;
       ssu.get(c.id).name = c.name;
       update updateSSU
              }else{
       SelfServiceUser s = new SelfServiceUser();
       s.username = c.ID__c;
       insert insertSSU
            }


Shashikant SharmaShashikant Sharma

What is your profile when you invoke this trigger. Is it a portal user?

Virtuoso123Virtuoso123

System Admin

Shashikant SharmaShashikant Sharma

Ok i just discovered that you can not update or create SelfServiceUser in Apex.

 

Here is your solution if you want it.

http://boards.developerforce.com/t5/Apex-Code-Development/Create-Enable-new-SelfServiceUser-when-contact-is-created/td-p/120070