Does lack of vitamin B12 or vitamin d cause anxiety and racing heart?

Unlikely. While low vitamin levels and poor nutrition can cause a whole host of issues its unlikely a direct cause and effect. The anxiety may cause the racing heart and the racing heart can create more anxiety . The cycle can feed on itself. The origin of the anxiety should be sought and treated.