I am also new to kegging, so take with a grain of salt.
I put a little in the keg, slosh around with lid on, and then set it upside down for few minutes to let sanitizer get all over the top parts real good. I then slosh it around again, hook up to my co2 tank and purge a little through my system. I then leave some co2 in the keg until I am ready to fill it. I release pressure and pour out any excess sanitizer and immediately fill it with beer trying to leave the co2 blanket in there as much as possible.
After the beer is carbonated, remember to dump first glass or two to get rid of the sanitizer in your lines. And the foam is no problem at all.