The development of a novel analytical technique, electrochemical X-ray fluorescence (EC-XRF), is described and applied to the quantitative detection of heavy metals in solution, achieving sub-ppb limits of detection (LOD). In EC-XRF, electrochemical preconcentration of a species of interest onto the target electrode is achieved here by cathodic electrodeposition. Unambiguous elemental identification and quantification of metal concentration is then made using XRF. This simple electrochemical preconcentration step improves the LOD of energy dispersive XRF by over 4 orders of magnitude (for similar sample preparation time scales). Large area free-standing boron doped diamond grown using microwave plasma chemical vapor deposition techniques is found to be ideal as the electrode material for both electrodeposition and XRF due to its wide solvent window, transparency to the XRF beam, and ability to be produced in mechanically robust freestanding thin film form. During electrodeposition it is possible to vary both the deposition potential (Edep) and deposition time (tdep). For the metals Cu(2+) and Pb(2+) the highest detection sensitivities were found for Edep = -1.75 V and tdep (=) 4000 s with LODs of 0.05 and 0.04 ppb achieved, respectively. In mixed Cu(2+)/Pb(2+) solutions, EC-XRF shows that Cu(2+) deposition is unimpeded by Pb(2+), across a broad concentration range, but this is only true for Pb(2+) when both metals are present at low concentrations (10 nM), boding well for trace level measurements. In a dual mixed metal solution, EC-XRF can also be employed to either selectively deposit the metal which has the most positive formal reduction potential, E(0), or exhaustively deplete it from solution, enabling uninhibited detection of the metal with the more negative E(0).