Fix a query that finds no rows
Assigning a query to one record throws when nothing matches.
Your task
Fix phoneFor so it returns null when no Account has that name, instead of throwing.
public class AS_1603269E2B24_AccountPhones {
public static String phoneFor(String accountName) {
Account match = [
SELECT Phone
FROM Account
WHERE Name = :accountName
LIMIT 1
];
return match.Phone;
}
}Requirements
- returnsThePhoneOfAMatch should pass
- returnsNullWhenNoAccountMatches should pass
- returnsNullForABlankName should pass
- returnsNullWhenTheMatchHasNoPhone should pass