Codementor Events

Salesforce – Winter 24

Published May 08, 2024

For the Platform Developer I Certification Maintenance (Winter ’24), you have a requirement to bind the variables.

Here we have the sample code that need to be modified inside of the method getContactIDWithBinds

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) {
    //do not modify any code above this line
    //implement the logic that will use bindVars to retrieve the contact's ID
    return null;
    }
}

Now you need to update the method above getContactIDWithBinds method

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) {
    //do not modify any code above this line
    //implement the logic that will use bindVars to retrieve the contact's ID
    String queryString =
        'SELECT ID FROM Contact WHERE lastName = :lastName AND title = :title LIMIT 1';
        List<Contact> Contacts = Database.queryWithBinds(
            queryString,
            bindVars,
            AccessLevel.USER_MODE
        );
      return Contacts[0].Id;
    }
}

Now save the class and go to trailhead and test the functionality.

Peace ✌️

Discover and read more posts from Sunil Kumar
get started
post commentsBe the first to share your opinion
Show more replies