• marko.tomic
  • NEWBIE
  • 45 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

Hai,

 

How to remove space from a string?

 

Shine

Hi to all,

 

I have this test method:

 

public static testmethod void testMe(){

    Profile p = [select id from profile where name='Standard User'];
      String randomName = string.valueof(Datetime.now()).replace('-','').replace(':','').replace(' ','');
       User u = new User(alias = 'standt', email=randomName + 'standarduser@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US', profileid = p.Id,
      timezonesidkey='America/Los_Angeles', username=randomName + 'standarduser@testorg.com');
      insert u;
    
     System.runAs(u) {
        System.debug('************');
        System.debug(UserInfo.getLocale());
        String s = '6,663.33';
        Decimal de = Decimal.valueOf(s);
        System.debug(String.valueOf(de));
      }

 

 

Problem:


This line of code fails even if the number is perfectly valid for specified local:

String s = '6,663.33';
Decimal de = Decimal.valueOf(s);

 

System.TypeException: Invalid decimal: 6,663.33

 

Why this breaks?

 

I tried to create an custom object with one field of type currency and with logged in user whose local is de_DE system failed while saving 6,663.33 but after I changed local to US it succeeded  just like I expected. Why it doesn't work like that in test methods also?

 

Thank you very much in advance!

 

Hai,

 

How to remove space from a string?

 

Shine

Hi to all,

 

I have this test method:

 

public static testmethod void testMe(){

    Profile p = [select id from profile where name='Standard User'];
      String randomName = string.valueof(Datetime.now()).replace('-','').replace(':','').replace(' ','');
       User u = new User(alias = 'standt', email=randomName + 'standarduser@testorg.com',
      emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
      localesidkey='en_US', profileid = p.Id,
      timezonesidkey='America/Los_Angeles', username=randomName + 'standarduser@testorg.com');
      insert u;
    
     System.runAs(u) {
        System.debug('************');
        System.debug(UserInfo.getLocale());
        String s = '6,663.33';
        Decimal de = Decimal.valueOf(s);
        System.debug(String.valueOf(de));
      }

 

 

Problem:


This line of code fails even if the number is perfectly valid for specified local:

String s = '6,663.33';
Decimal de = Decimal.valueOf(s);

 

System.TypeException: Invalid decimal: 6,663.33

 

Why this breaks?

 

I tried to create an custom object with one field of type currency and with logged in user whose local is de_DE system failed while saving 6,663.33 but after I changed local to US it succeeded  just like I expected. Why it doesn't work like that in test methods also?

 

Thank you very much in advance!

 

How i can get the layouts metadata from the apex controller ?

The metadata API has a method describeLayout() or getDescribeLayout() but i cannot make it works at the controller.

If that is not possible , how i can connect to the metadata api from the apex controller?

Thanks
Br1
  • October 15, 2008
  • Like
  • 0