You need to sign in to do that
Don't have an account?
Nagesh B 13
Unable to pass the challenge in trialhead for below issue
Hi all,
i have below requirement in trialhead.
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>'.
i have written below code, but when i check challenge it is giving error. like
'Challenge Not yet complete... here's what's wrong:
Executing the 'searchForContacts' method failed. Either the method does not exist, is not static, or does not return the expected contacts.
'Am i doing anything wrong? please correct me or guide on this.
public class ContactSearch {
public static List<Contact> searchForContacts(String sname,String postalcode)
{
List<Contact> Clist;
insert new Contact[]{new Contact(LastName='aint',MailingPostalCode__c='5600069'),
new Contact(LastName='aria',MailingPostalCode__c='5700085')};
clist=[select Id,Name from Contact Where LastName=:sname and MailingPostalCode__c=:postalcode];
return clist;
}
}
Thanks,
Nag.
i have below requirement in trialhead.
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>'.
i have written below code, but when i check challenge it is giving error. like
'Challenge Not yet complete... here's what's wrong:
Executing the 'searchForContacts' method failed. Either the method does not exist, is not static, or does not return the expected contacts.
'Am i doing anything wrong? please correct me or guide on this.
public class ContactSearch {
public static List<Contact> searchForContacts(String sname,String postalcode)
{
List<Contact> Clist;
insert new Contact[]{new Contact(LastName='aint',MailingPostalCode__c='5600069'),
new Contact(LastName='aria',MailingPostalCode__c='5700085')};
clist=[select Id,Name from Contact Where LastName=:sname and MailingPostalCode__c=:postalcode];
return clist;
}
}
Thanks,
Nag.
You can try below code for you Trailhead module, you have to use standard field MailingpostalCode
Please check the below code.
Open Execute anonymous window and you can pass lastname and postalcode.
Hope this helps you!
Best Regards,
Jyothsna
Please check the below links
https://help.salesforce.com/apex/HTViewHelpDoc?id=contacts_fields.htm&language=en_US
https://releasenotes.docs.salesforce.com/en-us/spring14/release-notes/rn_schema_compound_fields_address.htm
Best Regards,
Jyothsna
Address fields have long been a part of Salesforce, provided on many standard objects, such as Account, Contact, Quote, and User. Addresses are available as individual fields on the object, consisting of:
- City
- Country
- CountryCode (when state and country picklists are enabled)
- Latitude (beta)
- Longitude (beta)
- PostalCode
- State
- StateCode (when state and country picklists are enabled)
- Street
Some objects provide fields for multiple addresses. For example, Account provides for four different addresses. In this case, address field names are prefixed with the type of address, for example, BillingCity, MailingState, and so on.Hope this helps you!
Best Regards,
Deepthi