[SalesForce] Evaluation issue with the String class endsWith() method

We've started encountering evaluation issues with the endsWith() method. We are using a multi-select field called, "Product_Notification__c", which we pull back and split into a string array for evaluation (typical). In this case, I'm looking for a value of " CN" as a suffix for China.

To replicate the issue, I'm evaluating both the Project_Notification__c value from the Contact record, as well as, a String variable holding the same value.

Sample Code:

Contact myContact = [SELECT Id, Product_Notification__c from Contact where Id = '003500000265gH8'];
System.debug('### Contact Product Notications : ' + myContact.Product_Notification__c);
String[] lstValuesFromContactRecord  = myContact.Product_Notification__c.split(';');  

String notifications = 'RT AUS Maint/Outage - FTI; RT CN01 CN; RT SaaS P01797; TOF NM Maint/Outage; RT EU Maint/Outage - FTI; RT US Maint/Outage - FTI; Maint DEV FTI';
System.debug('### String Product Notications : ' + notifications );
String[] lstValuesFromString = notifications.split(';'); 

for(String n : lstValuesFromContactRecord)
{
    n = n.trim();
    System.debug('### Contact value : *' + n.toUpperCase() + '*');

    if (n.toUpperCase().endsWith(' CN'))
    {
        System.debug('### CN Type found');  
    }
}

for(String n : lstValuesFromString)
{
    n = n.trim();
    System.debug('### String value : *' + n.toUpperCase() + '*');

    if (n.toUpperCase().endsWith(' CN'))
    {
        System.debug('### CN Type found'); 
    }
}

Debug Log Results:

enter image description here

Notice the string value for "RT CN01 CN" evaluates as "true" but, the Contact multi-select field evaluates "RT CN01 CN" as "false"? Have I missed something trivial? We've had similar code in place for months, and this evaluation recently started failing.

I've also tried the contains() method with similar results. I've also tried explicit casting during assignment i.e. String[] lstValuesFromContactRecord = (String[])myContact.Product_Notification__c.split(';');

Edit 9/9 – I've tried the below assignment with same results.
String contactNoficiations = myContact.Product_Notification__c;
String[] lstValuesFromContactRecord = (String[])contactNoficiations.split(';');

Best Answer

It ended up being an issue with the picklist value after all. As crop1645 mentioned, it could have been a copy & paste issue from a web page. I wasn't able to verify that from the metadata value - it looked fine and seemed to evaluate to 10 characters. However, re-entering the picklist option has resolved our evaluation issue.

Thanks!

Related Topic