Hadithcore
Al-Adab Al-Mufrad, 38
sahih· Al-Albani

Abu Hurayra reported that the Messenger of Allah, (ﷺ), said, "When a person dies, all action is cut off for him with the exception of three things:

sadaqa which continues, knowledge which benefits, or a righteous child who makes supplication for him."

حَدَّثَنَا أَبُو الرَّبِيعِ، قَالَ‏:‏ حَدَّثَنَا إِسْمَاعِيلُ بْنُ جَعْفَرٍ، قَالَ‏:‏ أَخْبَرَنَا الْعَلاَءُ، عَنْ أَبِيهِ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ رَسُولَ اللهِ صلى الله عليه وسلم قَالَ‏:‏ إِذَا مَاتَ الْعَبْدُ انْقَطَعَ عَنْهُ عَمَلُهُ إِلاَّ مِنْ ثَلاَثٍ‏:‏ صَدَقَةٍ جَارِيَةٍ، أَوْ عِلْمٍ يُنْتَفَعُ بِهِ، أَوْ وَلَدٍ صَالِحٍ يَدْعُو لَهُ‏.‏

References2 variants
In-Book Reference
Book 1, Hadith 38
English Reference
Book 1, Hadith 38