King David is the only person Scripture describes as being "a man after [God's] own heart" (1 Samuel 13:14). This is mystifying, really, because we know David's story: he committed adultery with Bathsheba, got her husband drunk, killed him off, and did a lot of other things against the Lord.
Yet God said of him, "He's a man after My own heart." This doesn't mean David was perfect, because he obviously wasn't. But another way to translate that phrase would be "a man after God's own mind" or "a man to fulfill God's purposes." It was as if God was saying, "I know David's sin, but I see him with the potential to be something other than that."
This is most evident when you compare the books of 1 Chronicles and 2 Samuel, which both document parts of David's life. You'll find similarities between the two, but you'll also find differences. For instance, in 1 Chronicles, you read nothing about David's decade-long struggle with Saul. You read nothing of his sin with Bathsheba. And you read nothing about his son Absalom's rebellion.
Why is that? It's not to trick you, but for the sake of the audience to whom the author, Ezra, was writing—the post-captivity Jews who had returned to Jerusalem. Ezra wanted to write something that would encourage them to press on into the future, not be mortified because of the bad stuff that happened in the past. "Yes, you've had dark days," he would say, "but you have a bright future. God wants to do something with this nation."
Also keep in mind that 1 Chronicles is a divine editorial; the Holy Spirit is the divine author. This tells us that while history is one thing, His story is quite another. God can take your history and weave it into His story so that no matter how dark your past is, your future can be bright when He's in control of your life.
Think about the potential of that phrase—a man or a woman to fulfill God's purposes—in terms of your own life. Think of what God can do through you, a man or woman sold out to Him, no matter what your past is. Now, does that mean you'll be perfect? No. Will you be filled with flaws? Yes. But will you be a person of potential and influence whose heart is set on the things of the Lord? Yes—a man or woman after God's own heart.
God isn't like man. He doesn't see like man sees. "Man looks at the outward appearance, but the Lord looks at the heart" (1 Samuel 16:7). God looked at David—even with all his flaws—saw his potential, and chose him. Let that great truth encourage you today in your walk with the Lord.