Guest User

Untitled

a guest
Nov 14th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public static void assignOwnerId(List<Inventory__c> invList){
  2.  
  3. List<User> userList = new List<User>([SELECT SAP_External_Id__c, Id
  4. FROM User
  5. WHERE SAP_External_Id__c > '0' ]);
  6.  
  7. Map<String, String> userMap = new Map<String, String>();
  8.  
  9. for (User userLoop:userList) {
  10. userMap.put(userLoop.SAP_External_Id__c, userLoop.Id);
  11. }
  12.  
  13. for (Inventory__c invLoop : invList) {
  14. invLoop.RecordTypeID = ttiProductRecId;
  15. if (invLoop.SAP_Account__c != null && userMap.get(invLoop.SAP_Account__c) != null) {
  16. invLoop.OwnerID = userMap.get(invLoop.SAP_Account__c);
  17. }
  18. }
  19. }
  20.  
  21. public static void assignOwnerId(List<Inventory__c> invList){
  22.  
  23.  
  24. Set<String> sapAccountNumbers = new Set<String>();
  25. for (Inventory__c invLoop : invList) {
  26. if (invLoop.SAP_Account__c != null) {
  27. sapAccountNumbers.add(invLoop.SAP_Account__c);
  28. }
  29. }
  30.  
  31. if (sapAccountNumbers.isEmpty()) {
  32. return;
  33. }
  34.  
  35. Map<String, Id> userMap = new Map<String, Id>();
  36. for (User userLoop : [SELECT SAP_External_Id__c, Id
  37. FROM User
  38. WHERE SAP_External_Id__c
  39. IN :sapAccountNumbers]) {
  40. userMap.put(userLoop.TTI_SAP_Cust_No__c, userLoop.Id);
  41. }
  42.  
  43. for (Inventory__c invLoop : invList) {
  44. invLoop.RecordTypeID = ttiProductRecId;
  45. if (invLoop.SAP_Account__c != null && userMap.containsKey(invLoop.SAP_Account__c)) {
  46. invLoop.OwnerID = userMap.get(invLoop.SAP_Account__c);
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment