It can take a few weeks for the body to build immunity after getting vaccinated. So, it is possible to get infected with the new virus just before or after vaccination.