I think it is always true, and one can explicitly define the class as follows, at least in the compact case (this construction is surely well-known to some people, but I'm not sure where to find it written down).
Let $M^{2n}$ be an almost complex manifold and $L^n \subseteq M$ a totally real submanifold (of course in the symplectic/Lagrangian case you just pick a compatible almost complex structure before starting). Over $M$ we have the complex line bundle $$E := \Lambda^n_{\mathbb{C}} TM,$$ and over $L$ we have the real line bundle $$F := \Lambda^n_{\mathbb{R}} TL.$$ $F$ is a subbundle of $E|_L$ in the obvious sense.
If $L$ is oriented then we can define $\mu_L$ to be twice the Poincaré dual of the vanishing locus of a generic smooth section $s$ of $E$ such that $s|_L$ lies in $F$ and is nowhere-zero. In the non-orientable case, $F$ doesn't have a nowhere-zero section, but we can replace $E$ and $F$ by their tensor squares and then omit the factor of two after taking Poincaré duals. It is clear from these definitions that $\mu_L$ maps to $2c_1(X)$ in $H^2(X)$ and that when $L$ is orientable $\mu_L$ is divisible by $2$two. One can also check by hand that it does indeed induce the Maslov homomorphism.
Without assuming compactness of $M$ and $L$ one probably has to work a bit more; morally the definition has to be at least as hard as that of $c_1(X)$. You may also needs to make some reasonable assumption on the niceness of the embedding of $L$ in $M$. If the pair $(M, L)$ is a relative CW complex then $E$ (or its tensor square when $L$ is non-orientable) can be represented by a map $$M \rightarrow BU(1)$$ extended cell-by-cell from a constant map $L \rightarrow EU(1)$, by using $F$ (or its square) to give a canonical homotopy class of trivialisation over $L$. You could then define $\mu_L$ to be twice (or not) the class of the pullback of a cocycle representing $c_1$ of the tautological bundle. Here it's less obvious that this class is independent of choices and induces the Maslov homomorphism, but it can probably be checked.