Skip to main content

This is happening for Get Hands-on with Bind Variables in a SOQL Query Platform Developer I Certification Maintenance (Winter '24)

7 answers
  1. Jan 4, 2024, 8:25 AM

    @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;

    }

    }

    }

0/9000