At any affliction: bereavement, loss, bad news.
إِنَّا لِلَّهِ وَإِنَّا إِلَيْهِ رَاجِعُونَ، اللَّهُمَّ أْجُرْنِي فِي مُصِيبَتِي وَأَخْلِفْ لِي خَيْرًا مِنْهَا
Innā li-Llāhi wa innā ilayhi rājiʿūn. Allāhumma’jurnī fī muṣībatī wa akhlif lī khayran minhā
To Allah we belong and to Him we return. O Allah, reward me in my affliction and replace it for me with something better.
Sahih Muslim 918Its merit Umm Salama said it when Abū Salama died · Allah gave her better: the Prophet ﷺ himself.