In Swedish people often confuse de/dem(they/them kind of) and I honestly don't know exactly when to differentiate. You often learn to replace the word with another like vi/oss(we/us) to see if the sentence still sounds good and then you know the form you should use
De/dem is simply the subject form and the object form of the same word, they and them respectively. The reason for the common confusion surrounding the use of these, as it might not be quite clear to a non-swedish speaker, is that both of them are pronounced in the same way nowadays: "dom". As the comment above suggests, just using another subject/object pronoun such as vi/oss (we/us) usually works as they are clearly pronounced in different ways and therefore gets more automatically correct.
Why the words for they/them have evolved to both sound the same and not really that close to how either of them are written I do not know, but the wrong use in text annoys me quite a lot. Personally, I'm all for ditching the differentiation and just default to always writing "dom" as that better reflects the spoken language.
On another tangent, Swedes also often "särskriver" - write two words apart when they should be put together. A fun example of that that I've seen is "kassa personal" (~crappy staff) which really should be "kassapersonal" (checkout staff).
And even worse, using personal pronouns exclusively in subject form, e.g. "till han" ("to he") instead of in object form where suitable, e.g. "till honom" ("to him").
my go to for remembering which one to use is translating the sentence to english and if "the" or "they" is correct use "de" and if "them" is correct use "dem" (remember by thinking dem = them)