I am working on an application that pulls data from a custom object applications and a staging table called Staging UCRBoard data, and compares two formula fields called 'identifier_mesh__c' that combines two key identifiers to indicate if these records represent the same data. However, when I add all the staging mesh fields to a list and then check to see if that list contains the same identifiers as the applications, I am finding that it never returns true.
This is confusing the heck out of me, as I have confirmed in anonymous apex that if I query both tables for a record with the same identifier, and then check for equality of those fields, it returns true. However as soon as I start involving many records and comparing against the list, it doesn't find any even though I know they are there.
The relevant code is below
Id devRecordTypeId = Schema.SObjectType.Application__c.getRecordTypeInfosByName().get('UCR').getRecordTypeId();
// TODO: Change desc back to asc, changing them only to avoid large amounts of fee free data
List<Staging_UCRBoard_Data__c> pendingMods = [SELECT Id, name, Registration_Status__c, CreatedDate, IsMotorCarrier__c, IsBroker__c, Identifier_Mesh__c, IsFreightForwarder__c, IsLeasingCompany__c, IsMotorPrivateCarrier__c, FeeAmountPaid__c, Number_TruckTractors__c, Registration_Record_Time__c, Registered_Vehicle__c, Number_AdditionalVehicle__c, Number_PassengerVehicle__c, Registration_Year__c, status__c, Physical_Address__c, Physical_City__c, Physical_Country__c, Physical_State__c, Physical_Zip__c, Legal_name__c, usdot_number__c FROM Staging_UCRBoard_Data__c WHERE status__c = 'Pending' AND modification__c = 'Yes' ORDER BY Registration_Record_Time__c];
System.debug('Pending Mods =' + pendingMods);
List<Application__c> toModPos = [SELECT id, Filing_Year__c, Num_of_Additional_Vehicles__c, Num_of_Straight_Trucks_and_Tractors__c, Num_of_Motor_Coaches_School_Buses_Vans__c, Account__c, Account_USDOT__c, Amount_Due__c, Total_Number_of_Vehicles__c,Identifier_Mesh__c FROM Application__c WHERE RecordTypeId = :devRecordTypeId];
System.debug('toMod Pos= ' + toModPos);
List<Application__c> toMod = new List<Application__c>();
Map<String, List<String>> usdotAndRegYears = new Map<String, List<String>>();
// Creates and holds the equivalent of the identifier mesh field on staging to match staging records to applications
List<String> applicationMeshFields = new List<String>();
for(Staging_UCRBoard_Data__c pendInst : pendingMods){
applicationMeshFields.add(pendInst.Identifier_Mesh__c);
}
for(Application__c meshCheck : toModPos){
String mesh = meshCheck.Identifier_Mesh__c;
if(applicationMeshFields.contains(mesh)){
System.debug('HIT');
toMod.add(meshCheck);
}
}
pendingMods represents the staging data, and every identifier mesh is put into a the list applicationMeshFields as a string. I then go through each application record and check to see if that apps mesh field is present in the list. This should be true for most of the records, but again, is returning empty every time.
I have also tried doing this in a SOQL statement on application WHERE identifier_mesh__c IN :applicationMeshFields, but this was also unsuccessful.
I am not sure if I am not understanding something about how salesforce is comparing this data, or I am just overlooking a simple mistake in my code, but after being unsuccessful in getting to the bottom of it most the afternoon, I am hoping someone here might know whats going on.