The Messenger of Allah ﷺ said, "When you are present with someone dying or someone ill, say good words, for the angels say amen to what you say."She said, "When Abu Salama died, I came to the Prophet ﷺ and said, 'Messenger of Allah, Abu Salama has died.'He said, 'Say, O Allah, forgive me and him, and grant me a good successor in his place.'"She said, "So I said it, and Allah granted me one better than him in his place, Muhammad ﷺ."
حدثنا أبو معاوية قال حدثنا الأعمش عن شقيق
قال رسول الله ﷺ إذا حضرتم الميت أو المريض فقولوا خيرا فإن الملائكة يؤمنون على ما تقولون قالت فلما مات أبو سلمة أتيت النبي ﷺ فقلت يا رسول الله إن أبا سلمة قد مات فقال قولي اللهم اغفر لي وله وأعقبني منه عقبى حسنة قالت فقلت فأعقبني الله عز وجل من هو خير لي منه محمدا ﷺ
Its isnad is sahih. Muslim narrated it 2/131 no. 918, Abu Dawud 3/190 no. 3115, Tirmidhi 2/298 no. 977, and he said, hasan sahih, Nasai 4/4 no. 1825, Ibn Majah 1/465 no. 1447, and Abd bin Humayd 444 no. 1537.