Different folks will have varying approaches about how to paint a room. Generally, when a house is built, the builders prime the ceiling and walls first. Then they install the trim, caulk it, and prime and coat the trim. It would make sense then, that if you’re repainting a room, you should approach it in the same order. Although you might not be repainting the ceiling, it’s good to keep it in mind and repaint it every so often.
When you paint then, you’ll want to begin by painting the walls, and then the trim last. The reason this makes the most sense is that if anything splatters as you paint, you won’t have to reapply to cover up what was already taken care of.