5

I'm creating a custom field in my Case object, whose value is set based on a formula which compares 2 values in an IF statement. My problem however, is the comparison between these 2 doesn't seem to be working.

Here are my 2 values I'm comparing:

  • Case.RecordTypeId = 01230000000mn4qAAA
  • $Label.MyCompVal = 01230000000mn4qAAA

Both identical!

When I use the following formula however, my IF statement is incorrectly saying they're NOT identical, and thus assigning the value 'B':

if(RecordTypeId == $Label.MyCompVal, 'A', 'B')

My assumption is the Case.RecordTypeId field is somehow grabbing & comparing only the 1st 15 characters (18 chars total) against the full 18 characters of $Label.MyCompVal. The reason I say this is because I decided to change the output value of 'B', to show the value of both of these:

if(RecordTypeId == $Label.MyCompVal, 'A', RecordTypeId + ':' + $Label.MyCompVal)

My result is 01230000000mn4q:01230000000mn4qAAA

As you can see, RecordTypeId only contains the first 15 characters of its total 18, which is why I feel the comparison is failing.

Any idea why this is happening?

Thanks

4

The 18-character ID is case-safe, and the 15-character ID is case-sensitive. Generally speaking, in the Salesforce Classic UI, the 15-character ID is used, and when working through the APIs, the 18-character ID is used. Specifically, formulas referencing a record ID will get the 15-character ID.

You could solve your particular problem in a few ways:

  • only put the 15-character ID in the custom label
  • use LEFT($Label.MyCompVal,15) on the right side of your comparison
  • use CASESAFEID(RecordTypeId) on the left side of your comparison

CASESAFEID() is very useful, but it's also pretty expensive in terms of formula compile size, so I'd use that as the last resort.

1
  • Thanks, I ended up using LEFT($Label.MyCompVal,15) to solve my problem! – goalie35 Jan 25 '18 at 19:48
2

By default in formula we get 15 digit Id. There are many previous id for this.

But in your case you can use CASESAFEID() it expect a 15 digit id and return 18 digit Id. You can use to get id and then compare it.

1
  • 1
    Thanks for you response. This worked fine for me, but I ultimately ended up using LEFT() rather than CASESAFEID() to avoid any add'l compile size – goalie35 Jan 25 '18 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.