Someone on YourHub.com has posted a brief public service announcement regarding a clinic that will offer free x-rays of Halloween candy this year. The post is accompanied by an admittedly exaggerated image, which suggests that the problem of pins, needles, and razor blades inserted into treats is one of epic proportions. The truth is somewhat different: although there have been documented cases, they are few and far between, and seldom result in even minor injury.
As the Snopes.com website (an essential source for verifying/debunking urban legends) points out, there are no confirmed stories of poisoned halloween candy, but there are some cases were sharp objects were found. However, as Snopes's Barbara Mikkelson explains, there is a major difference between the two forms of contamination: poison is meant to kill; objects are at most meant to injure, and more likely meant to simply frighten.
Mikkelson cites a professor named Joel Best who tracked eight cases, almost all of them hoaxes. The authentic ones consist mostly of people finding a pin or a needle in a piece of candy, not of biting into it and being cut. Medical attention is seldom required; the worst incident required a few stitches.
Additionally, there is often good reason to believe that the child who "found" the needle and brought it to his parents may actually be the one who put the needle there, either as a way of getting attention or blaming it on someone else, or simply as a Halloween prank.
So, bottom line: it never hurts to be careful. But finding a needle in a Halloween treat is less likely than finding a needle in a haystack. Parents are well advised to exercise caution and even examine treats, especially home-made ones, but a free x-ray is mostly likely unnecessary.
Update, October 2020: Originally, this article linked to a photograph from the public service announcement discussed at top. Since that announcement has disappeared, along with the photo, we have replaced it with a iStockphoto photo by RileyMacLean, which accompanied this 2018 article in the Dallas News, which documented a local scare in 1982, spurred by the infamous 1982 case of Tylenol on store shelves being tainted with potassium cyanide. (Strangely, the article does not mention the brief razor blade scene in 1981's Halloween II.)