function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tarun MukhiaTarun Mukhia 

Apex Class is not working properly?

Hi,
We have a setup where Cases are automatically created and priority is set based on the predefined priority defination(Screenshot 1). I think this is the Class that runs this process( Below screenshots).
Process is not running properly.
45TC92 was reserved booked in both SC/SF and expected to be picked up yesterday 9/16/15 but SC/SF did not make a case for it or put it into priority. any idea why it did not create it's own case (Screenshot 2)

How can i find where the problem is?

User-added image
User-added image

Apex Class

  Map<Id, Part__c> records = new Map<Id, Part__c>();
        for (Part__c r : trailers) {
            Boolean isFleet = r.Ownership__c == 'Fleet';
            Boolean isDealership = r.Ownership__c == 'Dealership';
            Boolean isCustomer = r.Ownership__c == 'Customer';
            Boolean isRent = r.Account__c != null;
            Integer nextSafeties = r.Next_Safety_Date__c == null ? null : today.daysBetween(r.Next_Safety_Date__c);
            Integer nextCVI = nextSafeties;
            Integer nextPickup = r.Reservations__r == null || r.Reservations__r.isEmpty() ? null : today.daysBetween(r.Reservations__r[0].Pickup_Date__c);
            Integer sold = r.Sold_Date__c == null ? null : today.daysBetween(r.Sold_Date__c);
            Integer promised = trailerCheckOutTimes.containsKey(r.Id) ? today.daysBetween(trailerCheckOutTimes.get(r.Id)) : null;
            Integer lastFullService = r.Last_Full_Service_Date__c == null ? null : today.daysBetween(r.Last_Full_Service_Date__c);
            Decimal inServiceRate = inServiceRates.get(r.Branch__c + '|' + r.Trailer_Class__c);
            Boolean requiresPM = !r.Container_Trailer__c && nextSafeties < 90 && ((lastFullService > 180 && r.Location__c == 'Fleet East') || (r.PEP_Program__c != 'Y' && r.Location__c == 'Fleet West'));
            Boolean requirePDI = r.PDI_Date__c != null;
            Boolean requireRepair = trailerERS.contains(r.Id);
            Boolean isShort = r.Out_of_Service_Duration_Code__c == 'S';
            Boolean isMedium = r.Out_of_Service_Duration_Code__c == 'M';
            Boolean isLong = r.Out_of_Service_Duration_Code__c == 'L';
            Boolean isOOS = isShort || isMedium || isLong;
            Boolean isBlocked = r.Out_of_Service_Blocked_Code__c != null && r.Out_of_Service_Blocked_Code__c != 'N';
            Boolean inYard = r.Yard__c != null;
            Boolean excludeYard = excludedYards.contains(r.Yard__c);
            Boolean excludeClass = excludedClasses.contains(r.Trailer_Class__c);

            System.debug('Trailer --- isFleet: ' + isFleet + ', isDealership:' + isDealership + ', isCustomer:' + isCustomer + ', isRent:' + isRent + ', nextSafeties:' + nextSafeties + ', nextCVI:' + nextCVI + ', nextPickup:' + nextPickup + ', sold:' + sold + ', promised:' + promised + ', lastFullService:' + lastFullService + ', inServiceRate:' + inServiceRate + ', requiresPM:' + requiresPM + ', requirePDI:' + requirePDI + ', requireRepair:' + requireRepair + ', isShort:' + isShort + ', isMedium:' + isMedium + ', isLong:' + isLong + ', isOOS:' + isOOS + ', isBlocked:' + isBlocked + ', inYard:' + inYard);
            
            System.debug('Reservations: ' + r.Reservations__r);
            
            String priority = '99';
            if (excludeClass) {
                // Leave blank, already set to 99
            } else if (excludeYard) {
                priority = '15';
            } else if (isFleet && isRent && requireRepair) {
                priority = '1';
            } else if (isFleet && isRent && (requiresPM || nextCVI < 7)) {
                priority = '2';
            } else if (isFleet && nextPickup < 2 && isOOS) {
                priority = '3';
            } else if (isDealership && requirePDI && sold < 2) {
                priority = '4';
            } else if (isCustomer && promised < 2) {
                priority = '5';
            } else if (isFleet && nextPickup < 7 && (isLong || isMedium)) {
                priority = '6';
            } else if (isDealership && requirePDI && sold < 7) {
                priority = '7';
            } else if (isFleet && nextPickup == null && (nextSafeties < 30 || requiresPM)) {
                priority = '8';
            } else if (isCustomer && promised < 7) {
                priority = '9';
            } else if (isFleet && (isShort || isMedium) && !isBlocked && inServiceRate < 50) {
                priority = '10';
            } else if (isFleet && nextCVI < 60) {
                priority = '11';
            } else if (isDealership && requirePDI && nextPickup >= 8) {
                priority = '12';
            }

            if (r.Priority__c != priority) {
                records.put(r.Id, new Part__c(
                    Id = r.Id,
                    Priority__c = priority
                ));
            }
        }

        return records;
    }
}
 


 
Chandra Sekhar CH N VChandra Sekhar CH N V
Can you elaborate line 24 in details:
 
Boolean excludeClass = excludedClasses.contains(r.Trailer_Class__c);

your excludeClass variable is setting to true and getting default value as 99.