Skip to main content

Challenge looks at an Apex query method, however the challenge fails to insert its test records. Unsure what to do, because no debug logs are being generated either.

 

Challenge Link: Get Hands-on with Bind Variables in a SOQL Query Unit | Salesforce

Error Message: Challenge not yet complete in Mindful Impala Playground

An unexpected error occurred while inserting contact records and we couldn't check your work. Make sure Contact records can be inserted in this org, and click "Check Challenge" again. If this continues, contact the Trailhead Help team.

34 answers
  1. Dec 20, 2023, 7:21 AM

    I tried in two old and one new orgs, all get this error message. After changed the query string to:

    String queryStr = 'SELECT ID FROM Contact WHERE lastName = :lastName AND title = :title LIMIT 1';

     

    Works!

     

    FYI:

    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

    Id contactId = null;

    try {

    String queryStr = 'SELECT ID FROM Contact WHERE lastName = :lastName AND title = :title LIMIT 1';

    List<Contact> contacts = Database.queryWithBinds(queryStr, bindVars, AccessLevel.USER_MODE);

    if (contacts.size() > 0) {

    contactId = contacts[0].Id;

    }

    } catch (Exception ex) {

    system.debug(ex);

    }

    return contactId;

    }

    }

0/9000