Salatul Wahsha, also called Salatu Laylatil Dafn (the prayer of the first night after burial), is a prayer that is recited on the first night that a mu’min person has been buried. It is called Salatul Wahsha because on that night, the person buried feels fear and terror as a result of not being familiar with his new abode and the conditions that he faces. This salat, by the mercy of Allah (swt), will remove this fear from the newly deceased person. Therefore, in reality, this prayer isn't a prayer of fear as its title may imply, rather it is a prayer for the removal of wahshah and fear.
Now let us see what the Fuqaha (Jurists) have said about the specific rules of Salatul Wahsha.
1- In the first rakat Surah Hamd and then Ayatul Kursi (from الله لا اله الا هو‘Allahu la ilaha illa hu’ till و هو العلی العظیم ‘wa huwal aliyul adheem’ will suffice) are read (without reading Surah Tawheed). During the second rakat surah Hamd must be read and then surah Qadr (Inna Anzalnaho) is repeated 10 times. When the salat is finished we then say: “اللهم صل على محمد و آل محمد و ابعث ثوابها الى قبر فلان” (Allahuma Sale Ala Muhammadin wa Aale Muhammad wab’ath thawabaha ila qabre fulan), and in the place of the word fulan (which in Arabic means “so and so”) put the name of the deceased person.
2- In the first rakat after surah Hamd, Ayatul Kursi till the point of فیها خالدون ‘Feeha Khalidoon’ should be read once according to ehtiyat (precaution) and the rest is the same as above. Therefore, Imam Khomeini also hasn’t issued a fatwa on reciting till فیها خالدون‘ Feeha Khalidoon’ and only says it is a precaution.
Of course, there is also another prayer for the removal of the fear and hardship of the first night in the grave for the recently deceased that has been narrarated through hadiths by our Holy Prophet (S) in which he says: “There is no time more difficult for the deceased person than their first night in the grave; so have mercy on your deceased by paying charity on their behalf and if you’re not able to pay charity then pray two rakats of salat on their behalf like this: In the first rakat after surah Hamd, recite surah Tawheed twice and in the second rakat after surah Hamd, recite surah Takathur 10 times. After the Salat is finished say: اللهم صل على محمد و آل محمد و ابعث ثوابها الى قبر ذلک المیت فلان ابن فلان ‘Allahuma Sale Ala muhammadin wa Aale muhamad wabath thawabiha ila qabre dhallikal mayyit fulaan ibn fulaan’ (In place of the first “fulan” say the name of the deceased and in place of the second “fulan” recite the name of the deceased’s father). It is narrarated in traditions that this salat will cause ease for the deceased person and will also cause a widening of his grave till the Day of Judgement. The person who recites this salat will also have his good deeds increased and his rank in Allah's (swt) eyes raised.