NiO is a good candidate for ultrafast magnetic switching because of its large spin density, antiferromagnetic order, and clearly separated intragap states. In order to detect and monitor the switching dynamics, we develop a systematic approach to study optical second harmonic generation (SHG) in NiO, both at the (001) surface and in the bulk. In our calculations NiO is modeled as a doubly embedded cluster. All intragap d-states of the bulk and the (001) surface are obtained with highly-correlational quantum chemistry and propagated in time under the influence of a static magnetic field and a laser pulse. We find that demagnetization and switching can be best achieved in a subpicosecond regime with linearly rather than circularly polarized light. We also show the importance of including an external magnetic field in order to distinguish spin-up and spin-down states and the necessity of including magnetic-dipole transitions in order to realize the process in the centrosymmetric bulk. Having already shown the effects of phonons in the SHG for the bulk NiO within the frozen-phonon approximation, and following the same trail of thoughts, we discuss the role of phonons in a fully quantized picture as a symmetrylowering mechanism in the switching scenario and investigate the electronic and lattice temperature effects.