You need to sign in to do that
Don't have an account?
Error : Trailhead unit -> Apex Basics & Database --> Writing SOQL Queries
Question :
Create an Apex class that returns contacts based on incoming parameters
My answer:
public class ContactSearch {
public static List<Contact> searchForContacts(String lastName,String postalCode){
List<Contact> contacts = new List<Contact>();
contacts = [Select Id, Name from Contact
where LastName = :lastName
and MailingPostalCode like :('%'+postalCode+'%') ];
return contacts;
}
}
I tested the answer from dev console. it works fine..
But I get this error from Trialhead , why? and it is saying about deletion why?
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: Delete failed. First exception on row 0 with id 0031a00000EiCzvAAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Not authorized !!! : []
Create an Apex class that returns contacts based on incoming parameters
My answer:
public class ContactSearch {
public static List<Contact> searchForContacts(String lastName,String postalCode){
List<Contact> contacts = new List<Contact>();
contacts = [Select Id, Name from Contact
where LastName = :lastName
and MailingPostalCode like :('%'+postalCode+'%') ];
return contacts;
}
}
I tested the answer from dev console. it works fine..
But I get this error from Trialhead , why? and it is saying about deletion why?
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: Delete failed. First exception on row 0 with id 0031a00000EiCzvAAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Not authorized !!! : []
This kind of thing is the reason why you are encouraged to set up a new developer edition for trailhead.
All Answers
This kind of thing is the reason why you are encouraged to set up a new developer edition for trailhead.
NOTE:- Please deactivate Validation rule and Trigger from contact object.
Please let us know if this will help you.
Thanks
AMit Chaudhary
Yes Bob !! you are right.., there was a trigger that checked the contact before deletion.. Thats y it did not finish.So no problem with the code...
and I am using my dev edition only.
I wrote this trigger while practicing triggers..
Also I had to delete the trigger. So is there a way to temp disable it?
Thanks again..
public class ContactSearch
{
public static List<Contact> searchForContacts(String sLastName ,String sMailingPostalCode )
{
List<Contact> lstCont = [select Id , Name from contact where LastName =:sLastName
and MailingPostalCode =:sMailingPostalCode ];
return lstCont ;
}
}
There is no need to look for "lstCont". "Contacts" is enough. So you also need to adjust the String values for "LastName" and "MailingPostalCode".