The terminology you are looking for is scope. No, there's nothing at all wrong here, and this use in particular seems very appropriate. It would be inefficient to re-obtain the ID with your function each each time you are using it, and the scope of use is for the whole class.
In general, the scope should be determined by who needs to use the variable, and to some extent, as @Y Low says, the cost of creating it. That is, sometimes you might want to declare something outside the scope of a function even if the function is the only place it gets used.
For example, if you had a function that gets called thousands of times within your class (say, to format a value as a string in some special way), and it needed to declare some variables internally, it would be more efficient to declare them externally to the function, and reduce the overhead each time the function was called.
That may be TMI. In any event, in your case, though, since you say "id" is used elsehere in the class scope, it's entirely appropriate to define it there.