“Not everyone who says to Me, Lord, Lord,’ shall enter the kingdom of heaven, but he who does the will of My Father in heaven. Many will say to Me in that day, ‘Lord, Lord, have we not prophesied in Your name, cast out demons in Your name, and done many wonders in Your name?’ And then I will declare to them, ‘I never knew you; depart from Me, you who practice lawlessness!’”
The key to this verse is “he who does the will of My Father”.
You must know what the will of the Father is!
It’s definitely not based on prophesy, exorcism, and wonders done in “Your name”.
Let’s start with a basic from 2 Peter 3:9, which says God is not willing that any should perish but that all should come to repentance.
So the will of God is salvation for everyone, which He accomplished through Jesus Christ.
So does someone gain salvation?
Again, the Bible has the answer – for by grace you have been saved through faith, and that not of yourselves; it is the gift of God, not of works, lest anyone should boast. For we are His workmanship, created in Christ Jesus for good works, which God prepared beforehand that we should walk in them. Eph 2:8-10
Many people get a reverse order believing their works of prophesy, exorcism, and wonders lead to salvation. But it is salvation through Jesus that leads to these works.
Revelation says many stand before God and are judged by the things written in books.
I believe the books refer to the Bible and those judged by it fail in keeping the Law and the Prophets.
Salvation is not through good works but only through the good work that Jesus did for you.