Subha Todeyyaputta visits the Buddha at Jetavana and asks him why, among mankind, some are high and some low, some long-lived and some short, some handsome and some plain, some rich and some poor, etc. It is the result of their heritage from the past, answers the Buddha; their deeds are their possessions, their parents, their kindred and their refuge; he then proceeds to explain in detail (M.iii.202ff). Subha acknowledges the Buddha as his teacher.
The Commentary (MA.ii.962) calls this the Subha Sutta. For details of the circumstances in which the sutta was preached see Subha Todeyyaputta.