• ranjan nagaraju 7
  • NEWBIE
  • 25 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
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

 
public class JSONObject {
    public class value {


   }



public class JSONException extends Exception {}


public class JSONTokener {
   }

    public static  testmethod void test_valueToString() {
        /*
        Make sure that the JSON rendered by this class passes validation by parsers
        from http://json.org/json2.js and http://www.jsonlint.com.
        For example:    {foo: "bar"} is invalid
                        {"foo": "bar"} is valid
        */
    }

}
getting below exception 

Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 15 column 36


if i try adding @isTest method  end up with this error 
Compile Error: testMethod are by default IsTest at line 16 column 36

Can someone please help with this
 
@isTest
private class TestRemoveInterestingMomentLinebreaks 
{
    static testMethod void updateContactTest() 
    {
        Contact c = new Contact(lastname = 'test', Last_Interesting_Moment_Desc__c = '\n\r test');
        insert c;
        system.debug('updateContactTest Before value');
         system.debug(c.Last_Interesting_Moment_Desc__c.contains('\n\r'));
        system.assert(c.Last_Interesting_Moment_Desc__c.contains('\n\r') == false);
}
}

 
public with sharing class CustomObjectFactory
{
public class UserPrefsDefaults
  {
    public final String name = 'User Preferences';
    public final String bestBetsView = 'MBB';
    public final Integer maxPages = 5;
    public final Integer timeFrameDays = 3;
    public final Boolean showWhatIsNew = true;
  }
  
  public static UserPrefsDefaults userPrefsDefaults
  {
get{
  if (userPrefsDefaults==null){
  UserPrefsDefaults userPrefsDefaultsobj= new UserPrefsDefaults();
    //return userPrefsDefaultsobj;
  }
  return userPrefsDefaults;
  }

}}

on saving below test class im facing error 

@isTest
private class TestCustomObjectFactory 
{
    static testMethod void testUserPrefsGetter()
    {
        System.assertNotEquals(null, CustomObjectFactory.userPrefsDefaults);
        
        // test initialization
        CustomObjectFactory.userPrefsDefaults = null;
        System.assertNotEquals(null, CustomObjectFactory.userPrefsDefaults);
    }
    
    }

 
currently i'm trying to upgrade salesforce API version from 20 to 42.0. i'm having issue with below code which was compiling successfully earlier.
please help with above compile error and why its not throwing error @ line 22
public with sharing class CustomObjectFactory
{
public class UserPrefsDefaults
  {
    public final String name = 'User Preferences';
    public final String bestBetsView = 'MBB';
    public final Integer maxPages = 5;
    public final Integer timeFrameDays = 3;
    public final Boolean showWhatIsNew = true;
  }
  
  public static UserPrefsDefaults userPrefsDefaults
  {
    get {
      if(userPrefsDefaults == null) {
   Line 23--     userPrefsDefaults = new UserPrefsDefaults();
      }

      return userPrefsDefaults;
    }
  }
   
  }


 
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

 
public class JSONObject {
    public class value {


   }



public class JSONException extends Exception {}


public class JSONTokener {
   }

    public static  testmethod void test_valueToString() {
        /*
        Make sure that the JSON rendered by this class passes validation by parsers
        from http://json.org/json2.js and http://www.jsonlint.com.
        For example:    {foo: "bar"} is invalid
                        {"foo": "bar"} is valid
        */
    }

}
getting below exception 

Error: Compile Error: Defining type for testMethod methods must be declared as IsTest at line 15 column 36


if i try adding @isTest method  end up with this error 
Compile Error: testMethod are by default IsTest at line 16 column 36

Can someone please help with this
 
@isTest
private class TestRemoveInterestingMomentLinebreaks 
{
    static testMethod void updateContactTest() 
    {
        Contact c = new Contact(lastname = 'test', Last_Interesting_Moment_Desc__c = '\n\r test');
        insert c;
        system.debug('updateContactTest Before value');
         system.debug(c.Last_Interesting_Moment_Desc__c.contains('\n\r'));
        system.assert(c.Last_Interesting_Moment_Desc__c.contains('\n\r') == false);
}
}

 
public with sharing class CustomObjectFactory
{
public class UserPrefsDefaults
  {
    public final String name = 'User Preferences';
    public final String bestBetsView = 'MBB';
    public final Integer maxPages = 5;
    public final Integer timeFrameDays = 3;
    public final Boolean showWhatIsNew = true;
  }
  
  public static UserPrefsDefaults userPrefsDefaults
  {
get{
  if (userPrefsDefaults==null){
  UserPrefsDefaults userPrefsDefaultsobj= new UserPrefsDefaults();
    //return userPrefsDefaultsobj;
  }
  return userPrefsDefaults;
  }

}}

on saving below test class im facing error 

@isTest
private class TestCustomObjectFactory 
{
    static testMethod void testUserPrefsGetter()
    {
        System.assertNotEquals(null, CustomObjectFactory.userPrefsDefaults);
        
        // test initialization
        CustomObjectFactory.userPrefsDefaults = null;
        System.assertNotEquals(null, CustomObjectFactory.userPrefsDefaults);
    }
    
    }

 
currently i'm trying to upgrade salesforce API version from 20 to 42.0. i'm having issue with below code which was compiling successfully earlier.
please help with above compile error and why its not throwing error @ line 22
public with sharing class CustomObjectFactory
{
public class UserPrefsDefaults
  {
    public final String name = 'User Preferences';
    public final String bestBetsView = 'MBB';
    public final Integer maxPages = 5;
    public final Integer timeFrameDays = 3;
    public final Boolean showWhatIsNew = true;
  }
  
  public static UserPrefsDefaults userPrefsDefaults
  {
    get {
      if(userPrefsDefaults == null) {
   Line 23--     userPrefsDefaults = new UserPrefsDefaults();
      }

      return userPrefsDefaults;
    }
  }
   
  }