If only belief in Allah grants salvation, then how do Muslims think
that one could enter heaven before Muhammad and Islam existed?
God is the same as He was before the coming of the Prophet Muhammad. The word ‘Allah’ was used by the Arabs even before the advent of Islam, that is, even before the revelation of the Quran. Muhammad was not the first prophet of Islam, rather he was the last. Muhammad preached the same religion, as all the prophets who came before him, for example, Adam, Noah, Abraham, Jesus, Moses, etc. This has been mentioned in a verse in the Quran:
God has ordained for you the same religion which He enjoined on Noah, and which We have revealed to you, and which We enjoined upon Abraham and Moses and Jesus (Quran 42:13)
So, the God of the Torah, the Bible and the Quran is the same. God sent His prophets to every community in history to give guidance and only terminated His plan of sending prophets after the Book revealed to the Prophet Muhammad, the Quran, became preserved for later generations.
We raised among every people a messenger who enjoined, ‘Worship God alone and shun the evil one.’ (Quran 16:36)
Hence, it is not the case that only the followers of Islam will be granted salvation and Paradise. The Quran states:
The believers, the Jews, the Christians, and the Sabaeans—all those who believe in God and the Last Day and do good deeds—will be rewarded by their Lord; they shall have no fear, nor shall they grieve. (Quran 2:62)