1

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.

1 Answer 1

1

your code is fine and does what you think it should do. Maybe you have a data issue (case sensitivity?) or a field type mismatch for Identifier_Mesh__c across both objects.

Steps taken to confirm your code:
1) Created the two custom objects above (application__c, staging_ucrboard_data__c) with a similarly named text(255) field (identifier_mesh__c).
2) I simplified your SOQL to only focus on the mesh id field, and ran it. I observed a hit.

Consider this code:

public class betaFish {

public static List<Application__c> getApplicationsToMod() {
    Id devRecordTypeId = Schema.SObjectType.Application__c.getRecordTypeInfosByName().get('UCR').getRecordTypeId();
    List<Staging_UCRBoard_Data__c> pendingMods = [SELECT Id, name, Identifier_Mesh__c FROM Staging_UCRBoard_Data__c];
    System.debug('===== pendingMods: ' + pendingMods.size());
    List<Application__c> toModPos = [SELECT id, Identifier_Mesh__c FROM Application__c WHERE RecordTypeId = :devRecordTypeId];
    System.debug('===== toModPos: ' + toModPos.size());
    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);
    }

    System.debug('===== applicationMeshFields: ' + applicationMeshFields.size());

    for(Application__c meshCheck : toModPos){
        String mesh = meshCheck.Identifier_Mesh__c;
        if(applicationMeshFields.contains(mesh)){
            System.debug('HIT');
            toMod.add(meshCheck);
        }        
    }
    return toMod;
}

}

Simply call this code in execute anonymous to confirm a match:
System.debug(betaFish.getApplicationsToMod());

1
  • It appears it was my SOQL, as I was not getting a correct subset of records to compare against. Whoops! Thank you for taking a look and confirming, made it a lot easier to track down the issue when I knew where not to look. Commented Jan 10, 2019 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .