Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //list for storing all active assignemnts that are realted to the new forecast creations
- private List<pse__Assignment__c> assignmentList = new List<pse__Assignment__c>();
- /************************************************************************************************************
- // Name bulkBefore
- // Description Standard implementation of the TriggerHandler.bulkBefore() interface method.
- *************************************************************************************************************/
- public override void bulkBefore()
- {
- if (trigger.isDelete)
- {
- //store parent Levvel Forecast records that are about to be deleted
- list<Id> forecastIds = new list<Id>();
- for(SObject so :trigger.old)
- {
- Levvel_Forecast__c forecast = (Levvel_Forecast__c)so;
- forecastIds.add(forecast.id);
- }
- //Now we need to query all child Forecast Period records related to the Levvel Forecast we are about to delete
- forecastPeriodList = [SELECT Id, Levvel_Forecast__c FROM Forecast_Periods__c WHERE Levvel_Forecast__c IN: forecastIds];
- system.debug('List of Forecast Periods ' + forecastPeriodList);
- }
- if(trigger.isInsert)
- {
- //store the LevvelForecast record for update
- list<Id> forecastsToUpdate = new List<Id>();
- for(SObject so :trigger.new)
- {
- Levvel_Forecast__c newForecast = (Levvel_Forecast__c)so;
- if(newForecast.RecordTypeId == '0121N000000U6GYQA0' )
- {
- forecastsToUpdate.add(newForecast.employee__c);
- }
- }
- //Now we need to query all the assignments
- assignmentList = [SELECT id, pse__Resource__c FROM pse__Assignment__c WHERE pse__Resource__c IN: forecastsToUpdate];
- }
- }
- /************************************************************************************************************
- // Name beforeInsert
- // Description Standard implementation of the TriggerHandler.beforeInsert() interface method.
- *************************************************************************************************************/
- public override void beforeInsert (SObject so)
- {
- Levvel_Forecast__c newForecast = (Levvel_Forecast__c)so;
- loadAssignment(newForecast);
- }
- /************************************************************************************************************
- // Name beforeDelete
- // Description Standard implementation of the TriggerHandler.beforeInsert() interface method.
- *************************************************************************************************************/
- public override void beforeDelete(SObject so)
- {
- Levvel_Forecast__c oldForecast = (Levvel_Forecast__c)so;
- deleteForecastPeriods(oldForecast);
- }
- /************************************************************************************************************
- // Name loadAssignment
- // Description Helper method to validate resource requests on an opportunity
- *************************************************************************************************************/
- private void loadAssignment (Levvel_Forecast__c newForecast)
- {
- for (pse__Assignment__c ass :assignmentList )
- if(ass.pse__End_Date__c > newForecast.Today__c && ass.pse__Is_Billable__c == TRUE)
- {
- newForecast.employee__c = ass.pse__resource__c;
- }
- }
- /************************************************************************************************************
- // Name deleteForecastPeriods
- // Description Helper method to validate resource requests on an opportunity
- *************************************************************************************************************/
- private void deleteForecastPeriods (Levvel_Forecast__c oldForecast)
- {
- //Now we delete
- delete forecastPeriodList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement