To determine whether to use whoever or whomever, here is the rule: him + he = whoever him + him = whomever
Examples:
Give it to whoever/whomever asks for it first.
Give it to him. He asks for it first.
Therefore, Give it to whoever asks for it first.
We will hire whoever/whomever you recommend. We will hire him. You recommend him. him + him = whomever
We will hire whoever/whomever is most qualified. We will hire him. He is most qualified. him + he = whoever
Rule 2.
When the entire whoever/whomever clause is the subject of the verb that follows the clause, look inside the clause to determine whether to use whoever or whomever.