Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global salesRepProcessingBatch_Accounts (set<String> soldInTerrBatchRet , List<Sales_Territory_Mapping__c > accountTerrList)
- {
- soldInTerrBatch =soldInTerrBatchRet ;
- accountList = accountTerrList;
- system.debug('Updating global class accountList '+ accountList.size());
- system.debug('Updating global class accountList123456 '+ accountList.size());
- system.debug('Territory Id'+soldInTerrBatch);
- system.debug('Territory Id'+soldInTerrBatchRet );
- }
- //Start Method
- global Database.Querylocator start (Database.BatchableContext BC) {
- system.debug('before query ');
- 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
- //system.debug('after query ');
- }
- //Execute method
- global void execute (Database.BatchableContext BC, List<sobject> scope) {
- system.debug('execute ');
- List<Account> customerList = new List<Account>();
- List<Account> updtaedsalesRepList = new List<Account>();//List to hold updated customer
- if(!accountList.isEmpty())
- {
- system.debug('accountList '+accountList);
- for(Sales_Territory_Mapping__c salesTer : accountList)
- {
- for (sObject objScope: scope) {
- Account newObjScope = (Account)objScope ;//type casting from generic sOject to Shipping_Address__c
- if(salesTer.Role__c=='ISALM')
- {
- newObjScope.ISAL_M_ID__c = salesTer.Sales_Rep__c;
- }
- if(salesTer.Role__c=='FSALM')
- {
- //newObjScope.TerritoryNames__c='Updated Via FSALM Batch Job';
- newObjScope.Sales_Rep_M_ID__c = salesTer.Sales_Rep__c;
- newObjScope.AccTerritoryNameM__c = salesTer.SalesTerrMapName__c;
- }
- if(salesTer.Role__c=='FSALCS')
- {
- System.debug('FSALCS');
- newObjScope.Sales_Rep_CS_ID__c = salesTer.Sales_Rep__c;
- newObjScope.AccTerritoryNameCS__c = salesTer.SalesTerrMapName__c;
- }
- if(salesTer.Role__c=='ISALCS')
- {
- newObjScope.ISAL_CS_ID__c = salesTer.Sales_Rep__c;
- }
- updtaedsalesRepList.add(newObjScope);//Add records to the List
- System.debug('Value of updtaedsalesRepList '+updtaedsalesRepList);
- }
- }
- if (updtaedsalesRepList != null && updtaedsalesRepList.size()>0) {//Check if List is empty or not
- Database.update(updtaedsalesRepList);
- System.debug('List Size '+updtaedsalesRepList.size());//Update the Records
- }
- }
- }
- //Finish Method
- global void finish(Database.BatchableContext BC){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement