Untitled
unknown
plain_text
3 years ago
2.4 kB
8
Indexable
User u = new User();
u.firstName = firstName;
u.lastName = lastName;
u.Username = email;
u.Email = email;
u.CommunityNickname = CommunityNickNameUser;
String accountId;
// create Account
AccountName = firstName + ' ' + lastName + '_Account';
Account portalAccount = new Account();
portalAccount.Name = AccountName;
portalAccount.Phone = PhoneNumber;
insert portalAccount;
portalAccount.IsPartner = true;
update portalAccount;
//assign buyers
setUpAccountAsBuyer(portalAccount);
accountId = portalAccount.Id;
// create user
//predefined function
string userId = 'Abc';
system.debug(userId);
if (userId != null) {
if (password != null && password.length() > 8) {
// List<String> listOfPermissions = new List<String>{
// 'B2B_Commerce_Bike_Buyer'
// };
string userId2 = Site.createPortalUser(u, accountId, password);
system.debug(userId2);
list<String> listOfPermissions = new list<string>();
listOfPermissions.add('B2B_Commerce_Bike_Buyer');
//listOfPermissions.add('B2B_LE_Video_Player_Reader');
//we take this from available permission set to assign user from background.
CommunityUserPermissionSet(userId2, listOfPermissions);
ApexPages.PageReference pageRef = Site.login(username, password, null );
if(pageRef != null) {
resp.put('url',pageRef.getUrl());
return resp;
}
}
}
string Check = portalAccount.id + ' ' + userId;
return resp;
}
} catch (Exception e) {
system.debug('e.getMessage+ '+e.getMessage());
if(!Test.isRunningTest()) throw new AuraHandledException(e.getMessage());
return null;
}
}Editor is loading...