Who said on??? I said in the crack behind the wall. That is why spray foam has a long tube for application. If someone has to go into the wall for service spray foam isn’t going to be a problem.
Most of the time rodents will not go through expanding foam sealant, most of the time. If you use some steel wool and then inject the foam into steel wool that would keep even the adventurous rodents out. How much heat? Expanding foam should have a heat rating. If you are worried about just hot pipes you can get a little piece of pipe insulation and put that around the pipes first.