Hadithcore
Bulugh al-Maram, 582

Damrah bin Habib (one of the Tabi'in or the followers of the Companions) narrated, ‘They (the Companions that he met) recommended that after the grave is leveled and the people leave, that one should stand by the grave and say three times to the deceased, 'O so-and-so, say:

"There is no god but Allah”, 'O so-and-so, say: "Allah is my Lord, Islam is my din (religion), and Muhammad is my prophet.” Related by Sa'id bin Mansur.

وَعَنْ ضَمْرَةَ بْنِ حَبِيبٍ أَحَدِ التَّابِعِينَ قَالَ: { كَانُوا يَسْتَحِبُّونَ إِذَا سُوِّيَ عَلَى الْمَيِّتِ قَبْرُهُ, وَانْصَرَفَ اَلنَّاسُ عَنْهُ, أَنْ يُقَالَ عِنْدَ قَبْرِهِ: يَا فُلَانُ! قُلْ: لَا إِلَهَ إِلَّا اَللَّهُ.‏ ثَلَاثُ مَرَّاتٍ, يَا فُلَانُ! قُلْ: رَبِّيَ اللَّهُ, وَدِينِيَ الْإِسْلَامُ, وَنَبِيِّ مُحَمَّدٌ ‏- صلى الله عليه وسلم ‏-} رَوَاهُ سَعِيدُ بْنُ مَنْصُورٍ مَوْقُوفًا .‏ [1]‏ .‏

References2 variants
In-Book Reference
Book 3, Hadith 51
English Reference
Book 3, Hadith 607