18 Digit ID In Apex

ย
Here is something interesting in Apex which you need to be aware of!๐ข
See the below code ๐ต๏ธโโ๏ธ๐ต๏ธโโ๏ธ๐ต๏ธโโ๏ธ
๐๐ช๐ด๐ต<๐๐ฅ> ๐ช๐ฅ๐๐ช๐ด๐ต = ๐ฏ๐ฆ๐ธ ๐๐ช๐ด๐ต<๐๐ฅ>{'๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐','๐๐๐๐๐๐๐๐๐๐๐๐๐
๐๐ฃ'};//15 ๐ฅ๐ช๐จ๐ช๐ต ๐ช๐ฅ๐ด
๐ง๐ฐ๐ณ(๐๐ฅ ๐ช๐ฅ๐ช๐ต๐ฆ๐ฎ:๐ช๐ฅ๐๐ช๐ด๐ต){
๐๐บ๐ด๐ต๐ฆ๐ฎ.๐ฅ๐ฆ๐ฃ๐ถ๐จ(๐ช๐ฅ๐ช๐ต๐ฆ๐ฎ);
}
โ Note: Do not ever hardcode Id๐ซ. This code is just for demonstration purpose๐บ๐บ๐บ
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
This Content was originally posted in linkedin View Post