“When necessary” means like a medical necessity. As for the handshake, be creative and do your best to avoid it. Before they extend their hands, put your hand on your chest and greet them. And tell them I greet from my heart (and these days with COVID it’s easier to avoid the handshake).
Also you may see this clip:
https://youtu.be/kUKz7aLARwE
If you were in a position where you felt embarrassed to the point that you cannot handle the embarrassment, then due to the Law of No Difficulty you can shake their hands.