Skip to main content

Error: Unexpected token :ID

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;

    }

}

 

#Trailhead Challenges

2 respuestas
  1. 4 nov 2024, 21:21

    Hi ,

     

    Please try with the belwo 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) {

    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;

    }

    }

    }

    https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007UqPitSAF

0/9000