Guest User

Untitled

a guest
Jun 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. global class casedelete1 implements Database.Batchable<sObject>{
  2.  
  3. public Map<Id ,User> users;
  4.  
  5. global Database.QueryLocator start(Database.BatchableContext BC){
  6.  
  7. users = new Map<Id ,User>([Select id,FirstName,CompanyName, PN__c from User where id='00528000000Gmqe' ]);
  8. system.debug('@@@@@'+users);
  9. return Database.getQueryLocator([Select Id,Contactid,OwnerId from Case where OwnerId IN :users.keyset()]);
  10.  
  11. }
  12.  
  13.  
  14.  
  15. global void execute(Database.BatchableContext BC, List<Case> scope)
  16. {
  17.  
  18.  
  19. List<Id> objcaseIds = new List<Id>();
  20.  
  21. for(Case obj : Scope){
  22. objcaseIds.add(obj.Contactid);
  23. system.debug('casecontactids' +objcaseIds);
  24. }
  25.  
  26. Map<Id, Contact> objconId = new Map<Id, Contact>([SELECT Id, LastName,FirstName FROM Contact WHERE Id in :objcaseIds]);
  27. system.debug('contactids' +objconId );
  28. Contact objA=new contact();
  29. String tempPersonalnumber='';
  30. User tempusr=new User();
  31. for(Case objB : Scope){
  32.  
  33. tempusr = users.containskey(objB.ownerId) ? users.get(objB.ownerId) : null;
  34. tempPersonalnumber = tempusr == null ? tempPersonalnumber : string.valueof(tempusr.PN__c ) ;
  35.  
  36. if(tempPersonalnumber == Null || tempPersonalnumber =='')
  37. {
  38. tempusr=users.get(objB.OwnerId);
  39. system.debug('&&&'+tempusr);
  40. tempusr.CompanyName='XXXXX';
  41. system.debug('!!!!'+tempusr);
  42. users.put(objB.OwnerId,tempusr);
  43. system.debug('&&&&&'+users);
  44. objA = objconId.get(objB.Contactid);
  45. objA.LastName='XXXX';
  46. objconId.put(objB.Contactid, objA);
  47. // }
  48. //else
  49. {
  50. objA = objconId.get(objB.Contactid);
  51. objA.FirstName='XXXX';
  52. objconId.put(objB.Contactid, objA);
  53. }
  54.  
  55. }
  56. update objconId.values();
  57. Update users.values();
  58. system.debug('updatedcontcats' +objconId);
  59. delete Scope;
  60.  
  61.  
  62. }
  63.  
  64.  
  65.  
  66. global void finish(Database.BatchableContext BC)
  67. {
  68.  
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment