In a case that is subject to Sections 1812.10 and 2984.4 of the Civil Code, or subdivision (b) of Section 395 of the Code of Civil Procedure, or in an action or proceeding for an unlawful detainer as defined in Section 1161 of the Code of Civil Procedure:
(a)
The plaintiff shall state facts in the complaint, verified by the plaintiff’s oath, or the oath of the plaintiff’s attorney, or in an affidavit of the plaintiff or of the plaintiff’s attorney filed with the complaint, showing that the action has been commenced in the proper superior court and the proper court location for the trial of the action or proceeding, and showing that the action is subject to the provisions of Sections 1812.10 and 2984.4 of the Civil Code or subdivision (b) of Section 395 of the Code of Civil Procedure, or is an action for an unlawful detainer. When the affidavit is filed with the complaint, a copy thereof shall be served with the summons. Except as provided in this section, if the complaint or affidavit is not filed pursuant to this subdivision, no further proceedings may occur in the action or proceeding, except to dismiss the action or proceeding without prejudice. However, the court may, on terms that are just, permit the affidavit to be filed after the filing of the complaint, and a copy of the affidavit shall be served on the defendant and the time to answer or otherwise plead shall date from that service.
(b)
If it appears from the complaint or affidavit, or otherwise, that the superior court or court location where the action or proceeding is commenced is not the proper court or court location for the trial, the court where the action or proceeding is commenced, or a judge thereof, shall, whenever that fact appears, transfer it to the proper court or court location, on its own motion, or on motion of the defendant, unless the defendant consents in writing, or in open court (consent in open court being entered in the minutes of the court), to the keeping of the action or proceeding in the court or court location where commenced. If that consent is given, the action or proceeding may continue in the court or court location where commenced. Notwithstanding Section 1801.1 and subdivision (f) of Section 2983.7 of the Civil Code, that consent may be given by a defendant who is represented by counsel at the time the consent is given, and if an action or proceeding is subject to subdivision (b) of Section 395 or is for an unlawful detainer, that consent may only be given by a defendant who is represented by counsel at the time the consent is given.
(c)
In any case where the transfer of the action or proceeding is ordered under subdivision (a) or (b), if summons is served prior to the filing of the action or proceeding in the superior court or court location to which it is transferred, as to any defendant, so served, who has not appeared in the action or proceeding, the time to answer or otherwise plead shall date from service upon that defendant of written notice of the filing.
(d)
If it appears from the complaint or affidavit of the plaintiff that the superior court and court location where the action or proceeding is commenced are a proper court and court location for the trial thereof, all proper proceedings may be had, and the action or proceeding may be tried in that court at that location.
(e)
A motion for a transfer of the action or proceeding to a different superior court may be made as in other cases, within the time, upon the grounds, and in the manner provided in this title, and if upon that motion it appears that the action or proceeding is not pending in the proper court, or should for other cause be transferred, the action or proceeding shall be ordered transferred as provided in this title.
If any action or proceeding is ordered transferred to another court as provided in this section, proceedings shall be had, and the costs and fees shall be paid, as provided in Sections 398 and 399.
(f)
If a motion is made for transfer of an action or proceeding to a different court location within the same superior court as provided in this section, proceedings shall be had as provided by local rules of the superior court.