The I-485 would have to be rejected, or, you lose your job after the I-485 is filed. Even then if you maintain yourself for 6 months after the I-485 was filed and your employer doesn't withdraw the approved I-140, you can find a new job under AC21; or get lucky with no interview request or RFE.
The pain point is that you won't be able to travel after I-485 filing until your Advanced Parole turns up and you'll depend on EADs if you want to change jobs under AC21.
You could have your Green Card before you even win the H1-B lottery.