4. The zeros of the function $f(x)=x^{2}+a x+3 a$ are all integers, then the sum of all possible values of $a$ is
A. -4
B. 12
C. 4
D. 24
Given $x^{2}+a x+3 a=0$ has two roots $x_{1}, x_{2}$, by Vieta's formulas we get $\left\{\begin{array}{l}x_{1}+x_{2}=-a, \\ x_{1} x_{2}=3 a\end{array}\right.$ $\Rightarrow x_{1} x_{2}+3\left(x_{1}+x_{2}\right)=0 \Rightarrow\left(x_{1}+3\right)\left(x_{2}+3\right)=9 \Rightarrow( \pm 1) \times( \pm 9),( \pm 3) \times( \pm 3)$. Thus $\left(x_{1}, x_{2}\right)=(-2,6),(6,-2),(-4,-12),(-12,-4),(0,0),(-6,-6) \Rightarrow a=-4,16,0,12$, hence the sum of all values of $a$ is 24. Therefore, the answer is $D$.