Yahweh helped Jehoshaphat because when he started to rule Judah, he did the things that pleased Yahweh like his ancestor King David had done. He did not worship the idols of Baal.