Sefer Chasidim Siman 65
Can copy this into an AI, or connect the whole library to your assistant. For deeper learning, you can directly use the original seforim, sites, and apps.
וצדקתו עומדת לעד זה המזכה את הרבים כגון מלמד ליראי ה' תיקון תפילין לתקן לאחרים. אם זכית את הרבים ובא דבר עבירה על ידך ונתגברת על יצרך וניצלת הימנה אל תחזיק טובה לעצמך כי לא בתום לבבך נצלת כי חשך ה' אותם מחטוא לו לפי שזכית את הרבים:
“And his merit endureth forever” (Ps. 112:3). This refers to one who brings merit upon the community, for instance he teaches the God-fearing the correct preparation of phylacteries¹ enabling them to assist others. If you brought merit upon the community and a transgression presented itself to you, but you mastered your desire and were rescued from it be not proud of it. Not because of the completeness of your heart were you rescued but God withheld you from sinning against Him because you brought merit on the community.²
footnotes: ¹ Ketubah 50a. ² Aboth 5:21.