+ Start a Discussion
Prithviraj_ChavanPrithviraj_Chavan 

Site.createPortalUser(userObj, acc.Id, newSiteUser.password,false); retuns null

@RemoteAction
    public static String registerUser(String newUser){ 
        
        SiteUser newSiteUser = (SiteUser)System.JSON.deserialize(newUser, SiteUser.class);
        String userName = newSiteUser.email;
        try {
            Account acc = new Account();
            acc = [ SELECT Id FROM Account WHERE name = 'Customer' LIMIT 1];
            User userObj = new User(username = newSiteUser.email, 
                                    firstname= newSiteUser.firstname,
                                    lastname = newSiteUser.lastname, 
                                    email = newSiteUser.email,
                                    communityNickname = newSiteUser.firstname + '_'+Math.random(),
                                    alias = string.valueof(newSiteUser.firstname.substring(0,1) + 
                                                           newSiteUser.lastname.substring(0,1) + Math.random()),emailencodingkey='UTF-8',
                                                           languagelocalekey='en_US', 
                                                           localesidkey='en_US', 
                                                           timezonesidkey='America/Los_Angeles', 
                                    profileid = '00e0O000001xjVJ');
            System.debug('userObj		::	'+userObj);
            System.debug('acc		::	'+acc);
            String userId = Site.createPortalUser(userObj, acc.Id, newSiteUser.password,false);
            System.debug('User Created Successfully userId	::	'+userId);
        } catch(Site.ExternalUserCreateException ex) {
            List<String> errors = ex.getDisplayMessages();
            for (String error : errors)  {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, error));
                System.debug('Error Occurred	::	'+error);
            }
        }
        return null;
    }

Hi, I am creating a community user from custome registration page.. but not getting user id when using createPortal method