Troubleshooting Scripts: Holiday Schedules

Use the following script to find Resource records that have a Holiday Schedule selected, but are missing the underlying Holiday Time record.

// Query all resource records that have a holiday schedule selected
Map<Id, ResourceHeroApp__Resource__c> res = new Map<Id, ResourceHeroApp__Resource__c>([SELECT Id, Name, CreatedDate, ResourceHeroApp__Archive__c, ResourceHeroApp__Holiday_Schedule__r.Name FROM ResourceHeroApp__Resource__c WHERE ResourceHeroApp__Holiday_Schedule__c != NULL ORDER BY ResourceHeroApp__Holiday_Schedule__c DESC]);

// Query all holiday time records
List<ResourceHeroApp__Holiday_Time__c> hts = [SELECT Id, Name, ResourceHeroApp__Resource__c, ResourceHeroApp__Label__c FROM ResourceHeroApp__Holiday_Time__c];

// For each holiday time record, build a reference map between resource and the found holiday time record
Map<Id, Id> res_to_hts = new Map<Id, Id>();
for(ResourceHeroApp__Holiday_Time__c ht : hts) {
    res_to_hts.put(ht.ResourceHeroApp__Resource__c, ht.Id);
}

//Iterate through the list of resources and check to see if a holiday time record was found.  If not, add to the appropriate list based on whether the resource is archived or not
List<Id> missing_active = new List<Id>();
List<Id> missing_archive = new List<Id>();
for(Id re : res.keySet()) {
    if(!res_to_hts.containsKey(re)) {
        if(res.get(re).ResourceHeroApp__Archive__c) {
            missing_archive.add(re);
        }
        else {
            missing_active.add(re);
        }
        // system.debug(re + ' - ' + res.get(re).Name + ' - ' + res.get(re).CreatedDate + ' - ' + res.get(re).ResourceHeroApp__Archive__c + ' - ' + res.get(re).ResourceHeroApp__Holiday_Schedule__r.Name);
    }
}

//Print a count of each list
system.debug('missing_active:  ' + missing_active.size());
system.debug('missing_archive:  ' + missing_archive.size());

Use the following script to find Resource records that have a holiday schedule selected, but are missing the underlying Holiday Time Resource Assignment.

// Query all resource records that have a holiday schedule selected
Map<Id, ResourceHeroApp__Resource__c> res = new Map<Id, ResourceHeroApp__Resource__c>([SELECT Id, Name, CreatedDate, ResourceHeroApp__Archive__c, ResourceHeroApp__Holiday_Schedule__r.Name FROM ResourceHeroApp__Resource__c WHERE ResourceHeroApp__Holiday_Schedule__c != NULL ORDER BY ResourceHeroApp__Holiday_Schedule__c DESC]);

// Query all resource assignment records that are related to holiday time records
List<ResourceHeroApp__Resource_Assignment__c> ras = [SELECT Id, ResourceHeroApp__Resource__c FROM ResourceHeroApp__Resource_Assignment__c WHERE ResourceHeroApp__Holiday_Time__c != NULL];

// For each assignment, build a reference map between resource and the found assignment
Map<Id, Id> res_to_assign_ref = new Map<Id, Id>();
for(ResourceHeroApp__Resource_Assignment__c ra : ras) {
    res_to_assign_ref.put(ra.ResourceHeroApp__Resource__c, ra.Id);
}

//Iterate through the list of resources and check to see if a holiday time related assignment was found.  If not, add to the appropriate list based on whether the resource is archived or not
List<Id> missing_active = new List<Id>();
List<Id> missing_archive = new List<Id>();
for(Id re : res.keySet()) {
    if(!res_to_assign_ref.containsKey(re)) {
        if(res.get(re).ResourceHeroApp__Archive__c) {
            missing_archive.add(re);
        }
        else {
            missing_active.add(re);
        }
        // system.debug(re + ' - ' + res.get(re).Name + ' - ' + res.get(re).CreatedDate + ' - ' + res.get(re).ResourceHeroApp__Archive__c + ' - ' + res.get(re).ResourceHeroApp__Holiday_Schedule__r.Name);
    }
}

//Print a count of each list
system.debug('missing_active:  ' + missing_active.size());
system.debug('missing_archive:  ' + missing_archive.size());

Ready to get started?

Schedule a call to see if Resource Hero is right for you

Book now