If a body is at rest and no external force is acting then there will be no friction. The static friction comes when there is some external force acting on the body that tries to move the body. The body is in contact with the surface due to which the friction comes that opposes its motion. The force comes when you try to move that body, now if you have not applied more force than that can be offered by friction, the body will not move and still the frictional force will come. Consider a body lying on a plane surface, there is no frictional force when the body is at rest, now if you try to apply a small force on the body and try to move the body, then a frictional force will start appearing on the body at the contact point in the direction of which you are trying to move the body. If you are applying a small force , the body will not move and the value of frictional force will be same as the value of the force you are applying. The frictional force comes there is relative motion between the surface of the body and the contact layer or the body tries to have this relative motion.