This paper studies the random-coding exponent of joint source-channel coding for a scheme where source messages are assigned to disjoint subsets (referred to as classes), and codewords are independently generated according to a distribution that depends on the class of the source message. For discrete memoryless systems, two optimally chosen classes and product distributions are found to be necessary and sufficient to attain the sphere-packing exponent in those cases where it is tight.