Yes, you can sell your home while in bankruptcy.  But, you need to get the courts permission to sell the property. If your home was already scheduled for a sheriff sale, you may be able to avoid paying the sheriff's commission that would be due.   The motion to be made to sell the home is fairly complex.  We do not recommend trying this without an attorney.
When ever we help sell a property that is in foreclosure,  we make sure that the bank or the lender is paid in full. This would result in a couple things happening. First thing is that the lis pendans that was attached to the property will be discharged. The second thing is that you'll get a satisfaction a mortgage. The final thing is that the foreclosure action will be dismissed or a final judge will be vacated.
After these three items are taken care of, the foreclosure action will be dismissed.