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

How to enable self service portal automatically?

Hi there,

is it possible to automatically enable self-service portal for a contact? This could be done manually by clicking "enable self-service portal" standard button at the contact record. Could this be done automatically with an apex trigger?




I could see a SelfServiceUser object where in I can see creatable/updatable properties for this object.


I think you can automatically create self service user whenever you create a contact.


Here is the pseudo code and it might work for you.




for(contact c : trigger.New){
SelfServiceUser s = new SelfServiceUser();
s.ContactId =;
s.Email =;
s.FirstName = c.firstname;
s.IsActive = true;
s.LastName = c.LastName;
s.Username ='.ss';
insert s;






I have tried the trigger to make contact as a self service user or super user. It seems that DML operations are not allowed for self service user :


     trigger SelfUsercontrgger on Contact (after insert,before update)


     Contact con  =[0];

     Id contactid =;

     SelfServiceUser u = new SelfServiceUser(contactId=contactid, username=con.Email, firstname=con.FirstName,

     lastname=con.LastName, email=con.Email,languagelocalekey='en_US', localesidkey='en_US'


     insert u; //  DML operation not allowed here.



Hope this helps.



Thank you both for the answers! So basically the idea of the apex code is pretty simple, but at the moment INSERT is not supported by SF? And there is no other way to achieve this...


Hi there,


I really need to enable self service portal automatically.


Is there any way ? Or, simply it cannot be achieved ?


Please comment here..