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
ranjan nagaraju 7ranjan nagaraju 7 

issue on removing Linebreaks on fields.

User-added imageDEBUG log on 42.0 versionOn upgrading salesforce API  to 20.0(or 42.0) from 19.0 facing issue on removing Linebreaks on fields.

I ran my test case using API version  19 and 20.0(or 42.0) and attached the logs and test cases.

I found this thing weird 

On 19.0 version I’m running below code 

String  lastnametest = '\n\r testlastname';
String intmoment = '\n\r testintmoment';
        Contact c = new Contact(lastname = lastnametest,  Last_Interesting_Moment_Desc__c = intmoment );
Insert c;

Which on printing last name and Last_Interesting_Moment_Desc__c
trimming linebreaks its printing only testlastname and testintmoment.

And I have a trigger on insert to remove line breaks, this might not be useful in this case since  next line  is trimming.

But on salesforce version 20.0 (or 42.0)

Above statement on print  will print a blank line then it will print the values
But on printing this value in trigger the value is only text without  line break so it will not remove the line break which I need to achieve.

Attached the test class and trigger and results on running.

Please help thank you

 
ranjan nagaraju 7ranjan nagaraju 7
Test method :

@isTest
private class TestRemoveInterestingMomentLinebreaks 
{
    static testMethod void updateContactTest() 
    {
        String  lastnametest = '\n\r testlastname';
        String intmoment = '\n\r testintmoment';
        Contact c = new Contact(lastname = lastnametest,  Last_Interesting_Moment_Desc__c = intmoment );
        system.debug('Last_Interesting_Moment_Desc__c value  Before insert ' + c.Last_Interesting_Moment_Desc__c );
        system.debug('c.Last_Interesting_Moment_Desc__c.contains nextline Before insert ' + c.Last_Interesting_Moment_Desc__c.contains('\n\r'));
        system.debug('lastname value  Before insert ' + c.lastname );
        system.debug('c.lastname.containsnextline Before insert ' + c.lastname.contains('\n\r'));
        system.debug('contact hashcode before insert: ' + System.hashCode(c));
        insert c;
        system.debug('Last_Interesting_Moment_Desc__c value  After insert ' + c.Last_Interesting_Moment_Desc__c );
        system.debug('c.Last_Interesting_Moment_Desc__c.contains nextline After insert ' + c.Last_Interesting_Moment_Desc__c.contains('\n\r'));
        system.debug('lastname value  After insert ' + c.lastname );
        system.debug('c.lastname.contains nextline After insert ' + c.lastname.contains('\n\r'));
        system.debug('contact hashcode After insert: ' + System.hashCode(c));

        
        system.assert(c.Last_Interesting_Moment_Desc__c.contains('\n\r') == false);
    }


Trigger :

trigger RemoveInterestingMomentLinebreaksContact on Contact (before insert, before update) 
{
    try
    {
        for(Contact c : Trigger.new)
        {
          system.debug('inside trigger Last_Interesting_Moment_Desc__c value  Before replace ' + c.Last_Interesting_Moment_Desc__c );
        system.debug('inside trigger c.Last_Interesting_Moment_Desc__c.contains nextline Before replace ' + c.Last_Interesting_Moment_Desc__c.contains('\n\r'));
        system.debug(' inside trigger lastname value  Before replace ' + c.lastname );
        system.debug('inside trigger c.lastname.containsnextline Before replace ' + c.lastname.contains('\n\r'));
         System.debug('lead hashcode inside trigger: befor replace ' + System.hashCode(c));
            if(c.Last_Interesting_Moment_Desc__c != null)
                c.Last_Interesting_Moment_Desc__c = c.Last_Interesting_Moment_Desc__c.replaceAll('\r\n', ' ');
               system.debug('inside trigger Last_Interesting_Moment_Desc__c value  After replace ' + c.Last_Interesting_Moment_Desc__c );
        system.debug('inside trigger c.Last_Interesting_Moment_Desc__c.contains nextline After replace ' + c.Last_Interesting_Moment_Desc__c.contains('\n\r'));
        system.debug(' inside trigger lastname value  After replace ' + c.lastname );
        system.debug('inside trigger c.lastname.containsnextline After replace ' + c.lastname.contains('\n\r'));
         System.debug('lead hashcode inside trigger: After replace ' + System.hashCode(c));
        }
    }
    catch(Exception e)
    {
        system.debug(e);
    }
}