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

Using Site.CreatePortalUser(user, accountId,'password', true); Through Lightning ComponentHelperJs ?


I'm trying to create a portal user using Site.CreatePortalUser(user, accountId,'password', true) method of site class, making a call from my helper js but it's not working and not porviding me debug logs also.
Rajiv Penagonda 12Rajiv Penagonda 12
Can you paste your javascript code here?
public static void doInit(){
        String CurrentUserId = '00536000000yZu2';
        String ContactId = [Select contactid from User where id =: CurrentUserId].contactId;
        String AccountId  = [Select AccountID, OwnerId from Contact where id =: ContactId].AccountId;
        system.debug('@accountid... '+ AccountId);
        User testUser = new User();
        testUser.Username= '';
        testUser.Email = '';
        testUser.Lastname = 'LastName';
        testUser.Firstname = 'FirstName';
        testUser.Alias = 'test';
        testUser.CommunityNickname = '12346';
        testUser.UserRoleId = '00E36000000UkTy';
        testUser.ProfileId = '00e36000000d831';
        testUser.TimeZoneSidKey = 'GMT';
        testUser.LocaleSidKey = 'en_US';
        testUser.EmailEncodingKey = 'ISO-8859-1';
        testUser.LanguageLocaleKey = 'en_US';
        string userId = Site.createPortalUser(testUser, AccountId, 'Password',false);
        system.debug('@userid... '+ userId);
Javascript is working fine problem is in above code. Please look at that and try to run and let me know the solution if you have.
Rajiv Penagonda 12Rajiv Penagonda 12
From a casual glance, I see that you are trying to create two users on the same contact record. Not sure if the problem is because of that.

I found a similar discussion in another thread, extract below. Do confirm if this is not the case with you.

User-added image

Link to the thread here (