Supplication said upon seeing someone in trial or tribulation

On the authority of Abu Hurairah (radiallaahu ‘anhu), who said the Messenger of Allaah (salallaahu ‘alaihi wasallam) said, “If any man sees someone who is put to trial and says: Al Hamdu Lillahil-ladhee ‘Afanee Mimmabtalaka Bihi Wa Fadalanee ‘Ala Katheerin Mimman Khalaqa Tafdeelan, he wil not be affected by that affliction, whatever it was.” [At-Tirmidhi]

The definition of Al Hamdu Lillahil-ladhee ‘Afanee Mimmabtalaka Bihi Wa Fadalanee ‘Ala Katheerin Mimman Khalaqa Tafdeelan is: (All Praise and thanks be to Allaah, Who spared me from what he has afflicted you [with] and greatly preferred me to many of his creatures).