When electricity is passed through a pickle, it is conducted through Na+ and the Cl- ions that are present in the pickle. The electricity excites the electrons to a higher energy state, and when the fall back to ground state they emit a yellow/orange light.
When different ionic compounds are heated, electrons around the metal atom become excited and jump energy levels. When the electrons fall back to ground state they release light and heat energy. The amount of energy released determined the wavelength and color of the light released, resulting in different colored flames.