function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mrudula chintamanenimrudula chintamaneni 

Trailhead Challenge error in query

Hi,
Working on writing SOQL query module and got paused with this error. Following is the challenge, code and error for your consideration.

Challenge:
For this challenge, you will need to create a class that has a method accepting two strings. The method searches for contacts that have a last name matching the first string and a mailing postal code (API name: MailingPostalCode) matching the second. It gets the ID and Name of those contacts and returns them.
The Apex class must be called 'ContactSearch' and be in the public scope.
The Apex class must have a public static method called 'searchForContacts'.
The 'searchForContacts' method must accept two incoming strings as parameters, find any contact that has a last name matching the first, and mailing postal code matching the second string. The method should return a list of Contact records with at least the ID and Name fields.
The return type for 'searchForContacts' must be 'List<Contact>'.

Code:
public class ContactSearch {
    public static List<Contact> searchForContacts(String lastName, String mailingPostalCode){
        List<Contact> contacts=[select id, name from contact where LastName=:lastName and MailingPostalCode=:mailingPostalCode];
        return contacts;
    }
}

Error:
Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Enter email address properly while insert: []

Can anyone help me?
Please

Thanks
Mrudula
 
Best Answer chosen by mrudula chintamaneni
Amit Chaudhary 8Amit Chaudhary 8
It look like you created one validation rule on Contact object due to that issue is coming. Please deactivate the validation rule and try again.
 

All Answers

CloudGeekCloudGeek
Hi,

I just tested with the clas above you have written, it works well .

1. Try to log out and log in back , see if you could validate challenge again 
OR
2. Delete this class and create again , try to validate challenge now 


Your class looks good. 

 
Amit Chaudhary 8Amit Chaudhary 8
It look like you created one validation rule on Contact object due to that issue is coming. Please deactivate the validation rule and try again.
 
This was selected as the best answer
VamsiVamsi
Hi ,

from the below error it states that their seems to be some validation rules activated on that object for Email field. So deactivate all the validation and try again...........!!!!!
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Enter email address properly while insert: []
 
mrudula chintamanenimrudula chintamaneni
Thank you so much for the help. 
Yeah there is one trigger active. My bad i din't uncheck that. Now i passed the challenge but i couldn't see the result in developer console. I will keep trying a though. If you have any idea about this highlighted issue please help me.

Thanks in advance once again.
mani g 23mani g 23
Hi,

you can check no.of rows returned in log file.SOQL_EXECUTE_END [4]|Rows:1