The present invention provides a heterocyclic compound having an orexin type 2 receptor agonist activity.A compound represented by the formula (I): wherein each symbol is as described in the specification, or a salt thereof, is useful as an agent for the prophylaxis or treatment of narcolepsy.本發明提供具有食慾激素II型受體拮抗劑活性之雜環化合物。一種式(I)所示之化合物或其鹽,(其中,每個符號係如說明書中所述)其係可用於預防或治療猝睡症之藥劑。