Preheat the oven to 400 degrees F.
Bake the sweet potatoes in the middle of the oven for 45 minutes to 1 hour, or until tender. Let them cool. Peel the sweet potatoes and cut them diagonally into 1/4-inch slices.
In a bowl toss the apples with the lemon juice and arrange them with the sweet potato slices in a buttered 14-inch gratin dish. Sprinkle with the chestnuts.
In a stainless steel or enameled saucepan, cook the remaining ingredients over moderate heat, stirring, until the sugar is dissolved. Spoon the mixture oven the sweet potatoes and apples and bake the gratin in the middle of the oven, basting occasionally, for 30 minutes, or until the apples are just tender and the sweet potatoes are heated through.
The uncooked gratin can be assembled 1 day ahead and kept refrigerated, covered. Bake, uncovered, basting occasionally, for 40 minutes.
Put the gratin under a preheated broiler about 4 inches from the heat until the edges are browned lightly.