We consider an optimal control problem with the boundary functional for a Schrödinger equation describing the motion of a charged particle. By using the existence of an optimal solution, we search the necessary optimality conditions for the examined control problem. First, we constitute an adjoint problem by a Lagrange multiplier that is related to constraints of theory on symmetries and conservation laws. The adjoint problem obtained is a boundary value problem with a nonhomogeneous boundary condition. We prove the existence and uniqueness of the solution of the adjoint problem. Then, we demonstrate the differentiability of the objective functional in the sense of Frechet and get a formula for its gradient. Finally, we give a necessary optimality condition in the form of a variational inequality.