David was a man after Gods own heart. Yet he sinned. He coveted and slept with Uriahs wife Bathsheba, had Uriah killed, and took Bathsheba as his own. Where does any of this show that he was a man after Gods own heart? In Psalm 51 Davids heart is revealed. He repents of his sin and asks for restoration. God, in His mercy and compassion, restores David. That same mercy and compassion are available to us. Just like David, we need only ask.
Psalm 51:1-14
Psalm 51:1-14