Untitled
unknown
plain_text
2 years ago
4.1 kB
4
Indexable
public with sharing class RegisterController { static string firstName{get;set;} static string lastName{get;set;} static string email{get;set;} static string phone{get;set;} static string password{get;set;} static Map<String,boolean> valCheck{get;set;} @AuraEnabled(cacheable= true) public static Map<string,boolean> validatePhone(string inpPhone) { Map<String,boolean> result = new Map<String,boolean>(); result.put('phone',true); list<user> phoneList = [SELECT id,phone,email FROM user WHERE phone = :inpPhone AND phone != null WITH SECURITY_ENFORCED]; if(phoneList != null && !phoneList.isEmpty()) { result.put('phone',false); } return result; } @AuraEnabled(cacheable= true) public static Map<string,boolean> validateEmail(string inpEmail) { Map<String,boolean> result = new Map<String,boolean>(); result.put('email',true); list<user> mailList = [SELECT id,email FROM user WHERE email = :inpEmail WITH SECURITY_ENFORCED]; if(mailList != null && !mailList.isEmpty()) { result.put('email',false); } return result; } @AuraEnabled public static void createData(String firstName,string lastName,String phone,String email,String password) { String uniqueCommunityNickName = firstName+'.'+lastName+'@yopmail.com'; boolean condition = true; set<string> nickNameset = new set<String>(); for(user u : [SELECT id,communitynickName FROM user WHERE CommunityNickname != null WITH SECURITY_ENFORCED]) { nickNameset.add(u.CommunityNickname); } nicknameset.add(uniqueCommunityNickName); while(condition) { if(nickNameset.contains(uniqueCommunityNickName)) { uniqueCommunityNickName = createNickName(firstname,lastname); } else { condition = false; } } String accountId; Account portalAccount = new Account(); portalAccount.Name = firstName + ' ' + lastName +' Account'; portalAccount.phone = '630303303'; insert portalAccount; BuyerAccount buyeraccount = new BuyerAccount(); buyeraccount.name = portalAccount.name; buyeraccount.buyerId = portalAccount.id; buyeraccount.buyerStatus = 'Pending'; buyeraccount.commerceType = 'Buyer'; buyerAccount.creditStatus = 'Good Credit'; buyerAccount.isActive = true; insert buyerAccount; BuyerGroupMember member = new BuyerGroupMember(); member.BuyerId = portalAccount.id; member.BuyerGroupId = [SELECT id FROM buyerGroup WHERE name = 'Bicyclone Registered Buyer Group'].id; insert member; Contact contact = new Contact(); contact.firstName = firstName; contact.lastName = lastName; contact.email = email; contact.phone = phone; contact.Account= portalAccount; insert contact; User u = new User(); u.firstName = firstName; u.lastName = lastName; u.Username = email; u.Email = email; u.CommunityNickname = uniqueCommunityNickName; u.contactId = contact.id; accountId = portalAccount.Id; System.debug(accountId); String userId = Site.createPortaluser(u,accountId,password); } public static string createNickName(string firstname,string lastname) { String num = string.valueof(Integer.valueof(Math.random()*1000)); string name = firstname+'.'+lastName+'.'+num+'@yopmail.com'; return name; } public static string createAccountName(Strign firstname,string lastname) { string accountName = firstName+lastName+' account'; Account account =[SELECT id,name FROM account]; } }
Editor is loading...