Chemical analysis is a key aspect of forensic and pathological techniques. Modern instruments and procedures can pick up tiny traces of substances and identify materials found at, or removed from, a crime scene, as well as chemicals to which a victim has been exposed. This is not instantaneous magic, however. Many chemical analysis procedures are lengthy, involving complicated preparation stages before a sample can be run through an instrument and its identity confirmed. Below are some points relating to chemical analyses, some of which refer to errors I've spotted. More will be added over time.
Looking for clues
Crucially, the analyst has to know what to look for - different techniques are used for different substances and there is no black box which will spit out the exact identity of a completely unknown sample. Analysts will obviously know what to examine in, for instance, paint, fibre or seized drug samples. Identifying which chemicals someone has been exposed to would be much more difficult unless you have an idea of the substances which could be involved (e.g. solvents or metals used in industrial premises which someone may have worked in) or there are obvious clinical signs of poisoning or tissue damage. As I note in the section on poisons, the undetectable poison is the one you don't look for.
Time and money
As noted, some analytical procedures are lengthy and it could take weeks for the results to come back as the companies which provide forensic science services are often under pressure. They can also be expensive and impose a strain on diminishing police budgets so some tests would only be used for the most serious crimes. There are simple urine test kits, often used by employers to screen workers for drug use, and these are relatively cheap. They are not usually as sensitive as the tests carried out in a full-scale forensic laboratory - which are more expensive.
In England, the forensic science service has suffered badly following privatisation. At the time of writing, an investigation is underway into allegations of tampering with results at one company contracted to do this work (see http://www.telegraph.co.uk/news/2017/02/19/rogue-forensic-workers-feared-have-doctored-results-500-lab). Meanwhile, in Massachusetts, 21,587 criminal drug cases have been overturned by the state's highest court owing to misconduct by a forensic chemist who mixed up samples and falsified results. She spent three and a half years in prison when convicted in November 2013.
In some cases the analyst will look for breakdown products (metabolites) of a suspected poison rather than the poison itself. Nicotine, for instance, breaks down to cotinine, the presence of which in the blood indicates exposure to tobacco smoke, vaping clouds or nicotine poisoning. Similarly, the metabolite of Rohypnol can be detected post mortem rather than the original drug. For more on residue analysis see Hanging around in the Poisons section.
Some common materials are ionic - they split into two or more fragments, called ions, when they dissolve in water. This means that you would not find, for instance, potassium cyanide in the bloodstream or stomach: you would find cyanide ions. Potassium ions would be present but not discernible at the levels present from a fatal dose of potassium cyanide since they are there in the body naturally. The same argument applies to prussic acid (hydrogen cyanide) which splits into cyanide and hydrogen ions in solution.
The chemical record
Some substances are persistent in tissues and can provide an indication of someone's diet, exposure to pollutants and even where they grew up. Depending on the techniques used, nails, hair, bones and teeth can all provide information of this type. Isotope analysis of bone, for instance, can indicate a skeleton's provenance. Metals are useful in this context as they can be captured in teeth, bones and hair, but residues of drugs and other substances often remain in hair. Zopiclone, a sleeping drug, was found in Helen Bailey's hair in 2016 even after she had been submerged in a septic tank for three months, indicating that she had absorbed the drug prior to her murder (http://www.cambridge-news.co.uk/news/cambridge-news/traces-sleeping-drug-found-helen-12439381).
Soluble materials applied to the skin may be washed off easily unless they are absorbed in the surface or combine with the proteins in the skin. Silver nitrate, for instance, leaves a purple-black stain - this was used in the Graham Masterton novel Scarlet Widow to identify a thief - and we have all seen the yellow stains left on smokers' fingers by tobacco tars (not nicotine). Dyes often remain on the surface of the skin, too. You would not find highly soluble chemicals such as sodium hydroxide (caustic soda) on the skin of a corpse which had floated in a river for several hours, although the type of tissue damage caused by this particular material could give a clue to its former presence.
Tests can only get better
Analytical techniques have improved greatly over the years and continue to do so. DNA profiling, for instance, is now much quicker and more reliable than in 1986/7 when it led to the exoneration of an innocent suspect and the conviction of Colin Pitchfork for rape. Smaller quantities of many chemicals can now be detected than hitherto, so be careful if you are setting a story in the past. It would be worth talking to someone who has been doing the work for some time, in order to paint a credible picture.
Chemical analyses can lead to false conclusions, especially with the tests used in the past. One of the key factors which led to the Birmingham Six being wrongly convicted of a 1974 pub bombing was a test which purported to show that they had been handling explosives. Several types of explosives contain or consist of nitro compounds and the crude test used on the suspects' hands indicated that this had been the case. Unfortunately for them the test could not distinguish between explosive residues and traces of nitrocellulose, from a coating on the playing cards they had been using, which had migrated to their sweaty hands. Modern techniques can avoid such "false positives".
Seeds of doubt
In a recent experiment the TV presenter Angela Rippon tested positive for opiates despite having never used controlled substances. This was a result of her eating bread containing poppy seeds. These contain morphine alkaloids, although not in narcotic concentrations. A similar test, some years ago, on the Governor of Brixton Prison, following a spate of positive results on inmates, also proved positive and led to the cessation of poppy seed use in the prison bakery. See https://www.theguardian.com/lifeandstyle/2017/may/29 for the Rippon story.
DNA features heavily in many thrillers and also in real life detection. It has enabled the police to close cold cases, has helped to convict many guilty persons and - just as importantly - exonerated innocent suspects. So sensitive are modern techniques of collection and analysis of DNA-bearing samples that touching a glass that subsequently appears at a crime scene could mark you as a potential subject. Rather than go into details here I would urge you to get hold of the free booklet Making sense of forensic genetics published by the organisation Sense about Science. It's available via email@example.com (telephone +44 20 7490 9590) and is indispensable for anyone writing about DNA forensics.
The presence of someone's DNA at a crime scene does not necessarily mean that they are the culprit. The key question is "How did it get there?" The sample could have been there for some time or may have been transferred to the scene by someone else (secondary transfer). Work by the Jill Dando Institute at University College London has shown that gunshot residues could be transferred from someone who has fired a weapon to a second person and then on to a third, the last two of whom had never fired a gun.