This article didn’t go into it, but here’s a little background info from how some of these heavy metals end up in chocolate (at least):
The researchers found that cacao plants take up cadmium from the soil, with the metal accumulating in cacao beans as the tree grows. That’s similar to how heavy metals contaminate some other foods.
But lead seems to get into cacao after beans are harvested. The researchers found that the metal was typically on the outer shell of the cocoa bean, not in the bean itself. Moreover, lead levels were low soon after beans were picked and removed from pods but increased as beans dried in the sun for days. During that time, lead-filled dust and dirt accumulated on the beans. “We collected beans on the ground that were heavily loaded with lead on the outer shell,” DiBartolomeis says.