0

I don't understand how this is possible?

I have a simple custom metadata object with a number field (7,0) called Portal Id. The first record has a value of 20 in that field.

When I run this query I get different results in different orgs, but they are all on Winter 24:

Forms_and_Audience_Data__mdt [] cmd = [select label, Portal_Id__c
FROM Forms_and_Audience_Data__mdt];

System.debug(cmd[0].Portal_Id__c);

In one sandbox, this apex returns this value when I run a debug log: 20

But in Prod (which is also still on Winter 24), and another sandbox I get 20.0

Where's that trailing zero coming from in Prod?

1

1 Answer 1

2

Apex has a lot of internal "magic" that goes on, relative to some other languages.

For example, consider the following code:

Decimal a = 20;
Decimal b = 20.0;
System.debug(a); // 20
System.debug(b); // 20.0

This appears to be a problem with Object.toString/String.valueOf. If you need a specific format, you can use functions like intValue() or setScale(scale) to force them into compliance.

Decimal a = 20;
a = a.setScale(1);
Decimal b = 20.0;
System.debug(a); // 20.0
System.debug(b); // 20.0

As to why there are differences, it's impossible for an outsider to tell. It may be related to how old the records are, the underlying database format, patch versions, or something else.

1
  • Yeah - that's what caught me out - in the initial sandbox, it was treating it like an integer - so my string manipulation worked fine. In Prod, it was reading like 20.0, so the LPAD failed Feb 8 at 17:01

You must log in to answer this question.

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