After you have done something for His sake
Ibrāhīm and Ismāʿīl ﷺ said this while actually building the Kaʿbah.
وَإِذْ يَرْفَعُ إِبْرَٰهِـۧمُ ٱلْقَوَاعِدَ مِنَ ٱلْبَيْتِ وَإِسْمَـٰعِيلُ رَبَّنَا تَقَبَّلْ مِنَّآ ۖ إِنَّكَ أَنتَ ٱلسَّمِيعُ ٱلْعَلِيمُ
Rabbanā taqabbal minnā, innaka anta-s-Samīʿu-l-ʿAlīm.
“And [mention] when Abraham was raising the foundations of the House and [with him] Ishmael, [saying], "Our Lord, accept [this] from us. Indeed, You are the Hearing,1 the Knowing.2”
Where this comes from
They were raising the foundations of the House itself, and still asked for it to be accepted. Doing the work and knowing it might not be accepted are held together in one verse.
Source
The Qur'an · 2:127
Qur'an
- Qur'anic text in the Uthmani script via Quran.com; translation: Saheeh International