Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public without sharing class addController {
- @AuraEnabled
- public static void saveContacts(List<Contact> listContact){
- Insert listContact;
- system.debug('listContact '+ listContact);
- User currentUser = [SELECT Id, Contact.AccountId FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1];
- system.debug('currentUser '+ currentUser);
- List<User> uList= new List<User>();
- List<Relatie__c> rel= new List<Relatie__c>();
- UserRole ur = [SELECT Id FROM UserRole Where name = 'Partner'];
- Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Customer Community User' LIMIT 1];
- for(Contact con : listContact){
- Relatie__c rc = new Relatie__c(Account__c = currentUser.contact.AccountId, Contactpersoon__c = con.id ) ;
- system.debug('rc '+ rc);
- rel.add(rc);
- string alias = con.firstName.substring(0,1) + con.lastName.substring(0,1);
- user u = New user(userName = con.firstName+'.'+con.lastName+'@test.nl' ,
- firstName = con.firstName,
- lastName = con.lastName,
- alias = alias,
- email = con.Email,
- communityNickName = alias,
- timeZoneSidKey = 'Europe/Amsterdam',
- LocaleSidKey = 'nl_NL',
- EmailEncodingKey = 'ISO-8859-1',
- LanguageLocaleKey = 'nl_NL',
- ContactID = con.id,
- ProfileId = profileId.id,
- UserRoleId = ur.id
- );
- uList.add(u); }
- insert rel;
- system.debug('rel '+ rel);
- insert uList;
- }
- }
Add Comment
Please, Sign In to add comment