We can add that prayer can only be effective if it is done according to the perfect will of God: "And this is the confidence we have in him, that if we ask for a house according to his will, he hears us" 1Jn 5:14. One of the petitions in Jesus' model prayer, the Lord's Prayer, confirms it: "Thy will be done, as it is in heaven, so also on earth" Mt 6:10. In many cases the will of God is known because He has revealed it in the scriptures. Thanks @taty17.