كتاب الجنائز
11  
The Book of Prayer - Funerals
(2)
Chapter: What should be said at times of calamity?
(2)
باب مَا يُقَالُ عِنْدَ الْمُصِيبَةِ ‏
Sahih Muslim 918 b

Umm Salama, the wife of the Messenger of Allah (ﷺ), reported Allah's Messenger (ﷺ) as saying:

If any servant (of Allah) who suffers a calamity says:" We belong to Allah and to Him shall we return; O Allah, reward me for my affliction and give me something better than it in exchange for it," ' Allah will give him reward for affliction, and would give him something better than it in exchange. She (Umm Salama) said: When Abu Salama died. I uttered (these very words) as I was commanded (to do) by the Messenger of Allah (ﷺ). So Allah gave me better in exchange than him. i. e. (I was taken as the wife of) the Messenger of Allah (ﷺ).
وَحَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا أَبُو أُسَامَةَ، عَنْ سَعْدِ بْنِ سَعِيدٍ، قَالَ أَخْبَرَنِي عُمَرُ بْنُ كَثِيرِ بْنِ أَفْلَحَ، قَالَ سَمِعْتُ ابْنَ سَفِينَةَ، يُحَدِّثُ أَنَّهُ سَمِعَ أُمَّ سَلَمَةَ، زَوْجَ النَّبِيِّ صلى الله عليه وسلم تَقُولُ سَمِعْتُ رَسُولَ اللَّهِ صلى الله عليه وسلم يَقُولُ ‏ "‏ مَا مِنْ عَبْدٍ تُصِيبُهُ مُصِيبَةٌ فَيَقُولُ إِنَّا لِلَّهِ وَإِنَّا إِلَيْهِ رَاجِعُونَ اللَّهُمَّ أْجُرْنِي فِي مُصِيبَتِي وَأَخْلِفْ لِي خَيْرًا مِنْهَا إِلاَّ أَجَرَهُ اللَّهُ فِي مُصِيبَتِهِ وَأَخْلَفَ لَهُ خَيْرًا مِنْهَا ‏"‏ ‏.‏ قَالَتْ فَلَمَّا تُوُفِّيَ أَبُو سَلَمَةَ قُلْتُ كَمَا أَمَرَنِي رَسُولُ اللَّهِ صلى الله عليه وسلم فَأَخْلَفَ اللَّهُ لِي خَيْرًا مِنْهُ رَسُولَ اللَّهِ صلى الله عليه وسلم ‏.‏
Reference : Sahih Muslim 918b
In-book reference : Book 11, Hadith 5
USC-MSA web (English) reference : Book 4, Hadith 2000
  (deprecated numbering scheme)