Periapical granulomas are formed when the body tries to wall off an infection generating at the apex of the tooth.