Our actions are worthless to Allah (swt) if we do not intend it for His sake. We may gain some worldly benefit, feel happy, make some profit, or make a name for ourselves but with Allah (swt), the actions are only valid if it is purely serving and obeying Him.
As the hadeeth mentions, we will be exposed for our intentions when we are resurrected even if the acts are golden but the niyyah is tainted with a lust for admiration.
But Muslims have a habit of saying that “it’s in the heart” whenever they lack a duty in Islam. Whether it may be their excuses for not wearing the hijab, missing the salah for Fajr, or not attending Jumaa, they say that Allah knows what’s in the hearts and that they intend, inshAllah, to do whatever they lack in their deen.
It is true that Allah knows what’s in their hearts and Allah is the ultimate judge for this but intentions are followed by their actions. If it were “all in the heart,” Allah (swt) would not command us to pray or fast and do things that He loves. The proof is in the actions; intentions and actions are married to one another and one cannot flourish without the other.
A bad deed does not make it a good deed because of the intention. Once it is forbidden from Allah (swt) it will never be accepted as a good deed whether the niyyah was to create good. We cannot expect to sell alcohol and make the intention that we are collecting money to help fund the masjid. What we are doing from the beginning is unacceptable to Allah no matter the niyyah.