If, during the pendency of a proceeding in any other court, it is ascertained for the first time that exclusive jurisdiction lies within the juvenile and domestic relations district court, such court shall forthwith transfer the case, together with all papers, documents and evidence connected therewith, to the juvenile and domestic relations district court of the city or county having jurisdiction. The court making the transfer shall determine who is to have custody of the child pending action by the juvenile and domestic relations district court pursuant to § 16.1-247. If, during the pendency of a proceeding in the juvenile and domestic relations district court, it is ascertained for the first time that exclusive jurisdiction lies in the general district or circuit court, the juvenile and domestic relations district court shall likewise transfer the case to the appropriate court.
Va. Code § 16.1-245