Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
4
Indexable
Never
 @AuraEnabled
    public static String contactforGuestUser()
    {
        User u = New User();
		u.firstName = 'Jesus';
		u.lastName = 'Christ';
		u.CommunityNickname = 'JesusChristUnique@12322112122001';
		u.email= 'jchrist@yopmail.com';
		u.Username = u.email;

		Account account = new Account();
		account.name = 'Test Account 1002';
		insert account;

		String accountId = account.id;
		String password  = 'testing@123212';
        
        //Contact, User, User=> profile,
        
		string userId2 = Site.createPortalUser(u,accountId, password);
		System.debug(userId2);
        permissionsetGroup  pgroup = [SELECT id FROM permissionsetGroup WHERE developerName = 'customUser'];
        permissionsetAssign('0PGDR000000577v4AA',userId2);//permissionsetAssign(pgroup.id,userId2);
        
        ApexPages.PageReference pageRef = Site.login(u.username,password,'training202104--sverma.sandbox.my.site.com/s');
        
        return userId2 + '' +pageRef.getUrl();
    }
    
    @future
    public static void permissionsetAssign(String permissionsetGroupsID, Id userId)
    {
        ID psetGroupId = permissionsetGroupsID;
        List<PermissionSetAssignment> psAssignments= new List<PermissionSetAssignment>();
        PermissionSetAssignment assignment = new PermissionSetAssignment
        (
            PermissionSetGroupId = psetGroupId, AssigneeId = userId
        );
        insert assignment;
    }