I bought a 2007 Lariat and had the same problem (I did not buy it from a Ford dealer). The dealer had to take the truck to a Ford dealer so that they could extract the factory code from the vehicle's computer....cost: $150 CAD but since the dealer should have obtained the code from the previous owner, they covered the bill. All I had to do then is punch in the factory code and re-enter my own. Good luck.
2014 Denali 289RK - 2013 F-150 XTR, Ecoboost, SuperCab 6.5 foot box, 4x4, max tow pckg + Air Lift air bags