This is happening for Get Hands-on with Bind Variables in a SOQL Query Platform Developer I Certification Maintenance (Winter '24)
@Tanaveer Padeknoor
Can you check and save the below code
If the issue persists, you can follow the suggestions provided by @Piyusha Pilania
public class QueryContact {
public static Id getContactID(String lastName, String title) {
try{
Contact myContact = Database.query(
'SELECT ID FROM Contact WHERE lastName =:lastName AND title =:title LIMIT 1'
);
return myContact.Id;
} catch (Exception ex){
return null;
}
}
public static Id getContactIDWithBinds(Map<String, Object>bindVars) {
// Updated method using bind variables
String query = 'SELECT Id FROM Contact WHERE lastName = :lastName AND Title =:title LIMIT 1';
List<Contact> contacts = Database.queryWithBinds(query,bindVars,AccessLevel.USER_MODE);
if (contacts != null && !contacts.isEmpty()) {
return contacts[0].Id;
} else {
return null;
}
}
}