The Messenger of Allah ﷺ used to teach them, when they went out to the graveyards, that their spokesman should say, "Peace be upon you, people of these dwellings, from among the believers and the Muslims. We will, Allah willing, be joining you. We ask Allah for well-being for us and for you."
حدثنا محمد بن عباد بن آدم حدثنا أحمد حدثنا سفيان عن علقمة بن مرثد
كان رسول الله ﷺ يعلمهم إذا خرجوا إلى المقابر كان قائلهم يقول السلام عليكم أهل الديار من المؤمنين والمسلمين وإنا إن شاء الله بكم لاحقون نسأل الله لنا ولكم العافية
Reported by Muslim, in the Book of Funerals, chapter "What is to be said upon entering graveyards and the supplication for their inhabitants," hadith no. 975, from the hadith of Abu Ahmad Muhammad bin Abdullah, through the same chain.