Fix crash if invalid row given.

Now the function checks if the row exists in the contact id list, and returns null if it doesn't instead of crashing.