After I transfer my pokemon from sapphire to diamond than can I transfer my pokemon from diamond to heartgold before defeating the champion of heartgold?
Yes, that is possible if you have defeated the champion in Diamond.
But you don't migrate from Diamond to HeartGold, you have to trade. So if you go out and catch a bunch of Ratattas or something in HG then swap them for your pokemon in Diamond.
You can trade by posting up on the GTS with one game, finding the pokemon, and trading with the other, but it's easier to pal park from sapphire directly to HG. (unless you're just trying to complete the pokedex in both games.)