You need to sign in to do that
Don't have an account?
sairam v 9
Create an Apex class that returns contacts based on incoming parameters.?
I tried with below code but i am getting some error message .
public with sharing class ContactSearch {
public static List<Contact> searchForContacts(String lastName, String postalCode) {
return [ select Name from Contact where LastName = :lastName and MailingPostalCode = :postalCode ];
}
}
public with sharing class ContactSearch {
public static List<Contact> searchForContacts(String lastName, String postalCode) {
return [ select Name from Contact where LastName = :lastName and MailingPostalCode = :postalCode ];
}
}
How about trigger?Any active triggers on contact object?
Try this code
Thanks.
All Answers
It seems you have custom validation rule on the Contact.
Please check validation rules on contact with error message 'Hey!You are not authorised to perform this action'.
Deactivate it and try again.
Thanks.
I tried your code seems it showing same error message .
Hi Dilip,
In my org no Validation rules on Contacts object.
How about trigger?Any active triggers on contact object?
Try this code
Thanks.
I didn't inactive related trigger .
public class ContactSearch {
public static List<Contact> searchForContacts(String lastnm, String postcd){
List<Contact> cont = New List<Contact>();
cont = [Select Id, Name from Contact
WHERE (LastName =:lastnm and MailingPostalCode =:postcd)];
for (contact c:cont){
system.debug(c);
}
return cont;
}
}
for see the result of above apex class --> go to developer console --> debug--> open Execute Anonymouse window(crtl + E)
call you class static method by make sure you have a contact with last name 'Barr' and mailing postal code is '123456'. or you have any other contact.
execute this line and then check debug log wher you can see the result return by this apex class method
******
****
thanks hope it helps you :)
http://sfdcmonkey.com
ContactSearch.searchForContacts('ram', ' ');
http://sfdcmonkey.com