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 treatment of narcolepsy.