I love the 17th chapter of Jeremiah. There is so much good stuff here. This verse about the heart is a very BIG reason we need to trust G-d. We cannot even trust our own hearts. Feelings mean nothing in the scheme of things and can deceive us. The garden of eden is proof pudding but I'm sure all of us can think of a time that we were SURE about something only later to find out, we missed G-d entirely.
Joshua was a strong man of character and trusted G-d when no one else did. G-d had instructed Joshua to seek the L-rd's counsel above all and meditate on the law day and night (Joshua 1:9). Joshua served G-d as he led the Israelites through the battle at Ai and Jericho seeking the L-rd's counsel as he tried to do all Moses had commanded. But for some reason when the Gibeonites approached Joshua to make a covenant with the Israelites, vs 14 of chapter 9 tells us that Joshua did not ask for the L-rd's counsel. Perhaps Joshua trusted his own judgment at this point or listened to the pleas of his heart to have compassion on the these apparently poor and destitute travelers. Whatever the reason, Joshua's failure to seek the L-rd's counsel was a costly one and one we are still paying for it today.
G-d has established fences through His Torah instructions to protect us and guide us through life's trials. We can always test the motives of our heart by searching out G-d's counsel through His Word. If the thing we want to do does not line up with His word we can be confident that it isn't of Him. He will never put something on our heart that goes against His word. Several years ago a young man at church asked me to pray about his upcoming divorce. My husband and I had counseled this man on numerous occasions to try and work out his relationship with his wife. There wasn't any infidelity between them, the young man just wanted out of the marriage. So when he asked me to pray for the divorce, I gave him the only answer I could. I told him I could not pray contrary to G-d's word and His word clearly states that He hates divorce and remarrying would be causing both parties to commit adultery.
Needless to say, the young man was very angry and told me that G-d had told him he was to marry this other person. But I was able to have confidence in my words because in that situation I clearly knew G-d's will.
Some things are not always so clear or we may become confused. Still, we are to seek the L-rd's counsel and wait on Him. If we are truly seeking He will provide the answer through His word. The L-rd has set up a structure of authority as well such as the authority of the parent over the child until marriage or the husband over the wife. Hebrews 11:6 says that He is a rewarder to those that dilligently seek Him.