(Genesis 13:4) Rabbi Eleazar said: A person should always offer prayer before trouble comes. For had Abraham our father not offered prayer between Bethel and Ai in advance, no survivor or remnant would have been left of Israel. And it is written, "Will your cry avail when you are not in distress?" (Job 36:19) [meaning: arrange your plea before the distress, not only within it].
Abraham Prayed Before Trouble Arrived and Saved Israel's Survivors
Yalkut Shimoni on Torah 69:5
(בראשית יג ד) אָמַר רַבִּי אֶלְעָזָר, לְעוֹלָם יַקְדִּים אָדָם תְּפִלָּה לְצָרָה, שֶׁאִלְמָלֵי לֹא הִקְדִּים אַבְרָהָם אָבִינוּ תְּפִלָּה בֵּין בֵּית אֵל וּבֵין הָעַי לֹא נִשְׁתַּיְּרוּ מִיִּשְׂרָאֵל שָׂרִיד וּפָלִיט, וּכְתִיב (איוב לו, יט) "הֲיַּעֲרֹךְ שׁוּעֲךָ לֹא בְצָר".