First of all, it is unlikely that you will get them all the first time you play the campaign. That's why it is possible to go back after finishing the game. You can replay the level in any order you like to get the gems you have missed, also after getting all of the gems in a level you can quit, you won't lose them.