Optimal cross-sectional shapes for whisperinggallery mode sensors with prescribed emission wavelengths and resonance modes are generated through topology optimization based on the finite element method. The sensor is assumed to detect the state of the domain surrounded by the sensor. We identified the integral of the square of the electric field intensity over the detection domain and the quality factor (Q factor), which should be maximized, as key values for the sensor sensitivity, representing the detection limit for the relative permittivity change of the test object. Based on this, the integral of the square of the electric field intensity over the detection domain and the Q factor are studied as the optimization targets. In our numerical study, their optimal configuration characteristics are identified and analyzed. The resulting device has a small radius, a small detection domain and a concave shape with a center located next to the detection domain. We also succeeded in performing simultaneous optimization of the integral of the square of the electric field intensity over the detection domain and the Q factor.