What do you do if you didn't capture Heatran?

It depends on the game. The easiest thing is always to restore a save from right before the fight.

In Diamond, Pearl, and Platinum, you can run from the battle and it should be there when you come back. If you make him faint, it looks like he might be gone forever. You can either load whatever save you have, or trade for one.

In later games, often fighting the Elite Four will make legendaries reappear, or just waiting a day and re-finding the mirage spot where it appeared before.