It depends. If you had only saved the messages to your iPhone's local storage, you could only retrieve text messages deleted within the last 30-40 days. However, if you had backed up your messages to iCloud, you can retrieve all of them no matter when they got deleted. It's always better if you have recently backed up your messages to iCloud.