The fabrication and evaluation of a glassy carbon electrode (GCE) modified with self-doped polyaniline nanofibers (SPAN)/mesoporous carbon nitride (MCN) and bismuth for simultaneous determination of trace Cd2+ and Pb2+ by square wave anodic stripping voltammetry (SWASV) are presented here. The morphology properties of SPAN and MCN were characterized by transmission electron microscopy (TEM), and the electrochemical properties of the fabricated electrode were characterized by cyclic voltammetry (CV). Experimental parameters, such as deposition time, pulse potential, step potential, bismuth concentration and NaCl concentration, were optimized. Under the optimum conditions, the fabricated electrode exhibited linear calibration curves ranging from 5 to 80 nM for Cd2+ and Pb2+. The limits of detection (LOD) were 0.7 nM for Cd2+ and 0.2 nM for Pb2+ (S/N = 3). Additionally, the repeatability, reproducibility, anti-interference ability and application were also investigated, and the proposed electrode exhibited excellent performance. The proposed method could be extended for other heavy metal determination.