Monday, May 30, 2016

Crazy Mistakes in Development I - System.StringException: Invalid id

I have faced so many issues when I’m doing the development and could able to resolve almost all of them with the help of developer forum and SFSE. When I’m thinking of the time I had to spend for them and the difficulties I have faced, I thought to share those problems as well as the appropriate solutions that I could made. Because I believe it may save some other developer’s time.
I’ll keep updating this post series time to time when I catch more other birds.

Prob: System.StringException: Invalid id tempStr

1). Mostly this will happen when trying to assign query parameters into variables like below
If the value that has passed for accId is not in correct Id format, this exception will be thrown and hard to find out. It's better to assign the value to a variable type of String

or use try catch to validate properly

2). Also if you try to compare a variable type of Id with a String there's a chance of throwing this since the applied String is not in the standard Id format
To overcome this issue it can be used the string value of the Id to compare.