Set garlic heads and shallots in an 8- or 9-inch pan. Bake in a 375° oven until garlic and shallots are very soft when pressed, 35 to 40 minutes. Let cool.
Split baguette in half lengthwise.
Cut root end off garlic and squeeze out soft pulp; discard skin. Cut root end off shallots, peel, and discard skin; chop soft interior. Mix garlic and shallots and spread onto cut sides of baguette.
Peel, pit, and thinly slice the avocado. Lay slices over bottom baguette half and sprinkle lightly with salt and pepper.
Arrange cucumber, tomatoes, and basil leaves on avocado. Cover with top half of baguette. With a serrated knife, carefully cut sandwich into 3 or 4 portions.