Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. global salesRepProcessingBatch_Accounts (set<String> soldInTerrBatchRet , List<Sales_Territory_Mapping__c > accountTerrList)
  2. {
  3. soldInTerrBatch =soldInTerrBatchRet ;
  4. accountList = accountTerrList;
  5. system.debug('Updating global class accountList '+ accountList.size());
  6. system.debug('Updating global class accountList123456 '+ accountList.size());
  7. system.debug('Territory Id'+soldInTerrBatch);
  8. system.debug('Territory Id'+soldInTerrBatchRet );
  9. }
  10.  
  11. //Start Method
  12. global Database.Querylocator start (Database.BatchableContext BC) {
  13. system.debug('before query ');
  14. return Database.getQueryLocator('SELECT Id, Name, TerritoryId__c, Sales_Rep_CS_ID__c,Sales_Rep_M_ID__c,ISAL_CS_ID__c,ISAL_M_ID__c FROM Account WHERE TerritoryId__c In: soldInTerrBatch and KRM_Program__c =false');//Query which will be determine the scope of Records fetching the same
  15. //system.debug('after query ');
  16. }
  17.  
  18. //Execute method
  19. global void execute (Database.BatchableContext BC, List<sobject> scope) {
  20. system.debug('execute ');
  21. List<Account> customerList = new List<Account>();
  22. List<Account> updtaedsalesRepList = new List<Account>();//List to hold updated customer
  23. if(!accountList.isEmpty())
  24. {
  25. system.debug('accountList '+accountList);
  26. for(Sales_Territory_Mapping__c salesTer : accountList)
  27. {
  28. for (sObject objScope: scope) {
  29. Account newObjScope = (Account)objScope ;//type casting from generic sOject to Shipping_Address__c
  30. if(salesTer.Role__c=='ISALM')
  31. {
  32.  
  33. newObjScope.ISAL_M_ID__c = salesTer.Sales_Rep__c;
  34. }
  35. if(salesTer.Role__c=='FSALM')
  36. {
  37. //newObjScope.TerritoryNames__c='Updated Via FSALM Batch Job';
  38. newObjScope.Sales_Rep_M_ID__c = salesTer.Sales_Rep__c;
  39. newObjScope.AccTerritoryNameM__c = salesTer.SalesTerrMapName__c;
  40. }
  41. if(salesTer.Role__c=='FSALCS')
  42. {
  43. System.debug('FSALCS');
  44. newObjScope.Sales_Rep_CS_ID__c = salesTer.Sales_Rep__c;
  45. newObjScope.AccTerritoryNameCS__c = salesTer.SalesTerrMapName__c;
  46. }
  47. if(salesTer.Role__c=='ISALCS')
  48. {
  49. newObjScope.ISAL_CS_ID__c = salesTer.Sales_Rep__c;
  50. }
  51. updtaedsalesRepList.add(newObjScope);//Add records to the List
  52. System.debug('Value of updtaedsalesRepList '+updtaedsalesRepList);
  53. }
  54. }
  55. if (updtaedsalesRepList != null && updtaedsalesRepList.size()>0) {//Check if List is empty or not
  56. Database.update(updtaedsalesRepList);
  57. System.debug('List Size '+updtaedsalesRepList.size());//Update the Records
  58. }
  59. }
  60. }
  61.  
  62. //Finish Method
  63. global void finish(Database.BatchableContext BC){
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement