Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.88 KB | None | 0 0
  1. global with sharing class SchedularForBatchApex implements Schedulable {
  2. global void execute(SchedulableContext sc) {
  3. String CLASS_NAME1 = 'Ru_Actual__c';
  4. try {
  5.  
  6. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME1);
  7. Database.executeBatch(b);
  8.  
  9. }catch(Exception ex){
  10. system.debug('Exception in BatchTargtUpdate(Ru_Actual__c) Execute Process submision and error is--->'+ex);
  11.  
  12. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  13. }
  14. String CLASS_NAME2 = 'Revenue_Actual__c';
  15. try {
  16.  
  17. BatchTargtUpdate b1 = new BatchTargtUpdate(CLASS_NAME2);
  18. Database.executeBatch(b1);
  19.  
  20. }catch(Exception ex){
  21. system.debug('Exception in BatchTargtUpdate(Revenue_Actual__c) Execute Process submision and error is--->'+ex);
  22.  
  23. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  24. }
  25. String CLASS_NAME3 = 'Direct_Revenue_Actual__c';
  26. try {
  27.  
  28. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME3);
  29. Database.executeBatch(b);
  30.  
  31. }catch(Exception ex){
  32. system.debug('Exception in BatchTargtUpdate(Direct_Revenue_Actual__c) Execute Process submision and error is--->'+ex);
  33.  
  34. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  35. }
  36. String CLASS_NAME4 = 'Actual_Cost__c';
  37. try {
  38.  
  39. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME4);
  40. Database.executeBatch(b);
  41.  
  42. }catch(Exception ex){
  43. system.debug('Exception in BatchTargtUpdate(Actual_Cost__c) Execute Process submision and error is--->'+ex);
  44.  
  45. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  46. }
  47. String CLASS_NAME5 = 'Average_Deal__c';
  48. try {
  49.  
  50. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME5);
  51. Database.executeBatch(b);
  52.  
  53. }catch(Exception ex){
  54. system.debug('Exception in BatchTargtUpdate(Average_Deal__c) Execute Process submision and error is--->'+ex);
  55.  
  56. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  57. }
  58. String CLASS_NAME6 = 'Forecast_Actual__c';
  59. try {
  60.  
  61. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME6);
  62. Database.executeBatch(b);
  63.  
  64. }catch(Exception ex){
  65. system.debug('Exception in BatchTargtUpdate(Forecast_Actual__c) Execute Process submision and error is--->'+ex);
  66.  
  67. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  68. }
  69. String CLASS_NAME7 = 'Number_of_Won_Opportunities__c';
  70. try {
  71.  
  72. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME7);
  73. Database.executeBatch(b);
  74.  
  75. }catch(Exception ex){
  76. system.debug('Exception in BatchTargtUpdate(Number_of_Won_Opportunities__c) Execute Process submision and error is--->'+ex);
  77.  
  78. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  79. }
  80. String CLASS_NAME8 = 'Number_of_No_Decision_Opportunities__c';
  81. try {
  82.  
  83. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME8);
  84. Database.executeBatch(b);
  85.  
  86. }catch(Exception ex){
  87. system.debug('Exception in BatchTargtUpdate(Number_of_No_Decision_Opportunities__c) Execute Process submision and error is--->'+ex);
  88.  
  89. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  90. }
  91. String CLASS_NAME9 = 'Ru_Actual__c';
  92. try {
  93.  
  94. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME9);
  95. Database.executeBatch(b);
  96.  
  97. }catch(Exception ex){
  98. system.debug('Exception in BatchTargtUpdate(Ru_Actual__c) Execute Process submision and error is--->'+ex);
  99.  
  100. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  101. }
  102. String CLASS_NAME10 = 'Number_of_Closed_Opportunities__c';
  103. try {
  104.  
  105. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME10);
  106. Database.executeBatch(b);
  107.  
  108. }catch(Exception ex){
  109. system.debug('Exception in BatchTargtUpdate(Number_of_Closed_Opportunities__c) Execute Process submision and error is--->'+ex);
  110.  
  111. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  112. }
  113. String CLASS_NAME11 = 'Account_Revenue__c';
  114. try {
  115.  
  116. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME11);
  117. Database.executeBatch(b);
  118.  
  119. }catch(Exception ex){
  120. system.debug('Exception in BatchTargtUpdate(Account_Revenue__c) Execute Process submision and error is--->'+ex);
  121.  
  122. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  123. }
  124. String CLASS_NAME12 = 'Fulfillment_Form__c';
  125. try {
  126.  
  127. BatchTargtUpdate b = new BatchTargtUpdate(CLASS_NAME12);
  128. Database.executeBatch(b);
  129.  
  130. }catch(Exception ex){
  131. system.debug('Exception in BatchTargtUpdate(Fulfillment_Form__c) Execute Process submision and error is--->'+ex);
  132.  
  133. BatchUtil.trackErrorLogs(CLASS_NAME12, 'Execute',
  134. 'Exception Line Number:' + ex.getLineNumber() +
  135. '~ Exception Type-' + ex.getTypeName()+
  136. '~ Exception Message-' + ex.getmessage());
  137. }
  138.  
  139. try {
  140.  
  141. SalesPersonBatchTargtUpdate b16 = new SalesPersonBatchTargtUpdate('Revenue_Actual__c','Actual_Revenue_for_oppty');
  142. Database.executeBatch(b16);
  143.  
  144. }catch(Exception ex){
  145. system.debug('Exception in SalesPersonBatchTargtUpdate(Fulfillment_Form__c) Execute Process submision and error is--->'+ex);
  146.  
  147. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  148. }
  149.  
  150. try {
  151.  
  152. SFBatchTargetUpdate b17 = new SFBatchTargetUpdate();
  153. Database.executeBatch(b17);
  154. }catch(Exception ex){
  155. system.debug('Exception in SFBatchTargetUpdate() Execute Process submision and error is--->'+ex);
  156.  
  157. BatchUtil.trackErrorLogs(CLASS_NAME1, 'Execute', 'Exception Line Number:' + ex.getLineNumber() + '~ Exception Type-' + ex.getTypeName()+ '~ Exception Message-' + ex.getmessage());
  158. }
  159. }
  160.  
  161.  
  162. }
  163.  
  164. @isTest(SeeAllData='true')
  165. private class SchedularForBatchApexTest {
  166. public static Datetime dt = Datetime.now().addMinutes(1);
  167. public static String CRON_EXP = '0 '+ dt.minute() + ' * ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();
  168. public static testMethod void validateSchedularForBatchApex() {
  169. System.SchedulableContext SC;
  170. Database.QueryLocator QL;
  171. Database.BatchableContext BC;
  172. List<Target__c> tgtList=new List<Target__c>();
  173. Database.DMLOptions dml = new Database.DMLOptions();
  174. dml.DuplicateRuleHeader.AllowSave = true;
  175. //Record For BatchTargtUpdate
  176. Target__c t1=new Target__c(
  177. RecordTypeId =Schema.SObjectType.Target__c.getRecordTypeInfosByName().get('BCC').getRecordTypeId(),
  178. Financial_Year__c='FY2018',
  179. Vertical__c='Marketing',
  180. Forecast_Type__c='Monthly',
  181. Forecast_Period__c='B1-(Apr)',
  182. Bill_Target__c=1500000,
  183. Bill_Actual__c=1500000,
  184. Revenue_Target__c=1500000,
  185. Revenue_Actual__c=1500000,
  186. Direct_Revenue_Target__c=1500000,
  187. Direct_Revenue_Actual__c=1500000,
  188. Margin_Target__c=0.5,
  189. Strategic_Account__c=1500000,
  190. Fulfillment_Target__c=12,
  191. Contribution__c=1500000,
  192. Utilization_Target__c=0.5,
  193. Demand_Fulfillment__c=10,
  194. Forecast_Target__c=0.5,
  195. Forecast_Actual__c=0.5,
  196. Net_Win_Rate_Target__c=0.5,
  197. Average_Deal_Size_Actual__c=1500000,
  198. Rate_Target__c=0.5,
  199. Actual_Cost__c=1500000
  200. );
  201. tgtList.add(t1);
  202. Database.SaveResult sr=Database.Insert(t1,dml);
  203. if (sr.isSuccess()) {
  204. System.debug('Duplicate account has been inserted in Salesforce!');
  205. }
  206. BatchTargtUpdate obj=new GCPBatchTargtUpdate('Actual_Cost__c');
  207. SchedularForBatchApex obje=new SchedularForBatchApex();
  208. Test.startTest();
  209. Id jobId = System.schedule('Batch Apex Scheduler', CRON_EXP, new SchedularForBatchApex());
  210. System.assert(jobId != null);
  211. obje.execute(SC);
  212. Test.stopTest();
  213. }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement