The immune cells detect foreign cells due to the presence of antigens on the surface of foreign material. They are trained to differentiate antigens of endogenous substances and foreign substances.