You don't need the grep for ssh since you're looking for all users, that command would disclude any lines not including ssh. And I don't think that the ps -Af reports whether the user is an ssh user or not...
Btw, the 'man grep' says that grep has option '-c':
ps -Af | grep -c -i emacs
In your original pipe the 'ps -Af' creates list FOO.
The first grep takes list FOO and creates a shorter list BAR, where each line contains 'emacs'.
The second grep takes list BAR and creates a shorter list GAZ, where each line contains 'ssh'.
Therefore, the GAZ has only the lines of FOO that have both 'emacs' and 'ssh'.
I don't think that neither ps nor grep should write to stderr, just to stdout. The pipe feeds all stdout of ps to grep and due to the -c, the only thing that grep writes out is an integer.