Skip to main content

I am facing error while completing the PD 1 Maintenance module and getting below error. Please Help.

 

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.

4 respostas
  1. 27 de dez. de 2023, 12:30

    Hi @Ravikumar Rachure,

     

    Try this code:

     

    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;

    }

    }

    Hope this helps you.

     

    Regards,

    Jaiveer Jha

0/9000