Ja'far bin Muhammad (may Allah have mercy on him) narrates from his father (may Allah have mercy on him), and he from his grandfather (may Allah have mercy on him), that when the Messenger of Allah (peace and blessings be upon him) passed away, those offering condolence came, and they heard someone saying: In Allah Almighty there is consolation for every calamity, a replacement for every loss, and recompense for everything that is missed. So hold fast to Allah Almighty alone and place your hope in Him, for the truly afflicted one is he who has been deprived of the reward.
Its meaning has also been narrated through another route from Ja'far, from his father, from Jabir, and through another route from Anas bin Malik, and there is weakness in its chains. And Allah knows best.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 7091