Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. //list for storing all active assignemnts that are realted to the new forecast creations
  2. private List<pse__Assignment__c> assignmentList = new List<pse__Assignment__c>();
  3.  
  4. /************************************************************************************************************
  5. // Name bulkBefore
  6. // Description Standard implementation of the TriggerHandler.bulkBefore() interface method.
  7. *************************************************************************************************************/
  8. public override void bulkBefore()
  9. {
  10. if (trigger.isDelete)
  11. {
  12. //store parent Levvel Forecast records that are about to be deleted
  13. list<Id> forecastIds = new list<Id>();
  14. for(SObject so :trigger.old)
  15. {
  16. Levvel_Forecast__c forecast = (Levvel_Forecast__c)so;
  17. forecastIds.add(forecast.id);
  18. }
  19.  
  20. //Now we need to query all child Forecast Period records related to the Levvel Forecast we are about to delete
  21. forecastPeriodList = [SELECT Id, Levvel_Forecast__c FROM Forecast_Periods__c WHERE Levvel_Forecast__c IN: forecastIds];
  22. system.debug('List of Forecast Periods ' + forecastPeriodList);
  23. }
  24.  
  25. if(trigger.isInsert)
  26. {
  27. //store the LevvelForecast record for update
  28. list<Id> forecastsToUpdate = new List<Id>();
  29. for(SObject so :trigger.new)
  30. {
  31.  
  32. Levvel_Forecast__c newForecast = (Levvel_Forecast__c)so;
  33. if(newForecast.RecordTypeId == '0121N000000U6GYQA0' )
  34. {
  35. forecastsToUpdate.add(newForecast.employee__c);
  36. }
  37.  
  38. }
  39.  
  40. //Now we need to query all the assignments
  41. assignmentList = [SELECT id, pse__Resource__c FROM pse__Assignment__c WHERE pse__Resource__c IN: forecastsToUpdate];
  42.  
  43. }
  44. }
  45.  
  46.  
  47.  
  48. /************************************************************************************************************
  49. // Name beforeInsert
  50. // Description Standard implementation of the TriggerHandler.beforeInsert() interface method.
  51. *************************************************************************************************************/
  52. public override void beforeInsert (SObject so)
  53. {
  54. Levvel_Forecast__c newForecast = (Levvel_Forecast__c)so;
  55.  
  56. loadAssignment(newForecast);
  57. }
  58.  
  59.  
  60. /************************************************************************************************************
  61. // Name beforeDelete
  62. // Description Standard implementation of the TriggerHandler.beforeInsert() interface method.
  63. *************************************************************************************************************/
  64. public override void beforeDelete(SObject so)
  65. {
  66. Levvel_Forecast__c oldForecast = (Levvel_Forecast__c)so;
  67.  
  68. deleteForecastPeriods(oldForecast);
  69. }
  70.  
  71.  
  72. /************************************************************************************************************
  73. // Name loadAssignment
  74. // Description Helper method to validate resource requests on an opportunity
  75. *************************************************************************************************************/
  76. private void loadAssignment (Levvel_Forecast__c newForecast)
  77. {
  78.  
  79. for (pse__Assignment__c ass :assignmentList )
  80. if(ass.pse__End_Date__c > newForecast.Today__c && ass.pse__Is_Billable__c == TRUE)
  81. {
  82. newForecast.employee__c = ass.pse__resource__c;
  83. }
  84. }
  85.  
  86. /************************************************************************************************************
  87. // Name deleteForecastPeriods
  88. // Description Helper method to validate resource requests on an opportunity
  89. *************************************************************************************************************/
  90. private void deleteForecastPeriods (Levvel_Forecast__c oldForecast)
  91. {
  92. //Now we delete
  93. delete forecastPeriodList;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement