Supplication to be Recited When You Hear Someone Died

Imam Sadiq (A.S) narrated from his ancestors and from the holy Prophet (PBUH) that he said: whenever you hear the news of the death of your Muslim brother, you should say: 

(إِنَّا للهِِ وَ إِنَّا إِلَيْهِ رَاجِعُونَ) اللَّهُمَّ اكْتُبْهُ عِنْدَكَ فِي الْمُحْسِنِينَ وَ اجْعَلْ كِتَابَهُ فِي عِلِّيِّينَ وَ اخْلُفْ عَلَى تَرِكَتِهِ فِي الْغَابِرِينَ وَ اغْفِرْ لَنَا يَا رَبَّ الْعَالَمِينَ وَ لاَتَحْرِمْنَا أَجْرَهُ وَ لاَ تَفْتِنَّا بَعْدَهُ 

(Verily, we are from Allah and verily we return to Him) O’ Lord! Write down his name among the benefactors near You and put his book (book of his deeds) in the highest heaven and be his successor among his living household and forgive us O’ the Lord of the worlds and do not deprive us from his rewards and do not put us in sedition after him,
For sure, reading this prayer completes the reward of calamity as God the Almighty wishes and thanks belongs to the Lord of the worlds.

 Mustadrak al-Wasa’il and Mustatan al-Masa’il, vol. 2, p. 476