Guest User

Untitled

a guest
Feb 13th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. public without sharing class addController {
  2. @AuraEnabled
  3.  
  4. public static void saveContacts(List<Contact> listContact){
  5. Insert listContact;
  6. system.debug('listContact '+ listContact);
  7.  
  8. User currentUser = [SELECT Id, Contact.AccountId FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1];
  9. system.debug('currentUser '+ currentUser);
  10.  
  11. List<User> uList= new List<User>();
  12. List<Relatie__c> rel= new List<Relatie__c>();
  13. UserRole ur = [SELECT Id FROM UserRole Where name = 'Partner'];
  14.  
  15. Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Customer Community User' LIMIT 1];
  16.  
  17. for(Contact con : listContact){
  18.  
  19. Relatie__c rc = new Relatie__c(Account__c = currentUser.contact.AccountId, Contactpersoon__c = con.id ) ;
  20. system.debug('rc '+ rc);
  21. rel.add(rc);
  22. string alias = con.firstName.substring(0,1) + con.lastName.substring(0,1);
  23. user u = New user(userName = con.firstName+'.'+con.lastName+'@test.nl' ,
  24. firstName = con.firstName,
  25. lastName = con.lastName,
  26. alias = alias,
  27. email = con.Email,
  28. communityNickName = alias,
  29. timeZoneSidKey = 'Europe/Amsterdam',
  30. LocaleSidKey = 'nl_NL',
  31. EmailEncodingKey = 'ISO-8859-1',
  32. LanguageLocaleKey = 'nl_NL',
  33. ContactID = con.id,
  34. ProfileId = profileId.id,
  35. UserRoleId = ur.id
  36. );
  37.  
  38. uList.add(u); }
  39. insert rel;
  40. system.debug('rel '+ rel);
  41. insert uList;
  42.  
  43. }
  44. }
Add Comment
Please, Sign In to add comment