18 Digit ID In Apex

ย 

Here is something interesting in Apex which you need to be aware of!๐Ÿ“ข

See the below code ๐Ÿ•ต๏ธโ€โ™€๏ธ๐Ÿ•ต๏ธโ€โ™€๏ธ๐Ÿ•ต๏ธโ€โ™€๏ธ

๐˜“๐˜ช๐˜ด๐˜ต<๐˜๐˜ฅ> ๐˜ช๐˜ฅ๐˜“๐˜ช๐˜ด๐˜ต = ๐˜ฏ๐˜ฆ๐˜ธ ๐˜“๐˜ช๐˜ด๐˜ต<๐˜๐˜ฅ>{'๐ŸŽ๐ŸŽ๐Ÿ๐†๐๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ๐Ÿ‘๐„๐Ž๐Œ๐ˆ๐Ÿ–','๐ŸŽ๐ŸŽ๐Ÿ๐†๐๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ๐Ÿ‘๐„๐Ž๐…๐œ๐ฃ'};//15 ๐˜ฅ๐˜ช๐˜จ๐˜ช๐˜ต ๐˜ช๐˜ฅ๐˜ด
 ๐˜ง๐˜ฐ๐˜ณ(๐˜๐˜ฅ ๐˜ช๐˜ฅ๐˜ช๐˜ต๐˜ฆ๐˜ฎ:๐˜ช๐˜ฅ๐˜“๐˜ช๐˜ด๐˜ต){
 ๐˜š๐˜บ๐˜ด๐˜ต๐˜ฆ๐˜ฎ.๐˜ฅ๐˜ฆ๐˜ฃ๐˜ถ๐˜จ(๐˜ช๐˜ฅ๐˜ช๐˜ต๐˜ฆ๐˜ฎ);
 }

What do you think the debug will look like๐Ÿ”Ž? Will the ids in debug log look same as we entered๐Ÿ”Ž?

ย 

  • ๐Ÿ‘‰Nope you will find the ids are logged as 18 digit ids!
  • ๐Ÿ‘‰Did you know that in Apex, when you work with Salesforce IDs (like adding them to a ๐˜“๐˜ช๐˜ด๐˜ต<๐˜๐˜ฅ>), Salesforce automatically converts 15-character IDs to 18-character Ids and that is why this is happening.
  • ๐Ÿ‘‰Still you can use ๐˜“๐˜ช๐˜ด๐˜ต<๐˜š๐˜ต๐˜ณ๐˜ช๐˜ฏ๐˜จ> if you dont want this to happen.

See below to view the output

Image 1

This Content was originally posted in linkedin View Post