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
Mayank Deshpande 22Mayank Deshpande 22 

facing problem in debugging apex.

i write code to search a contact ----- wnat to debug this code in developer consol , but not able to do the same 
Public Class ContactSearch{
List <Contact> Con = New List<Contact>();
Public List<Contact> searchForContacts (String A, String B){
Con = [ Select Id , FirstName,LastName from Contact where lastname='A' and MailingPostalCode='B'];
return (Con);}
}
in developer consol i write one apex class and called a method of contact search class but getting error Line: 1, Column: 1
Unexpected token 'Public'.

Public Class NewContactSerach {
    
    ContactSearch Contc = New ContactSearch ();
    Contc.searchForContacts(Deshpande.abcde);
}

plz suggest me how to overcome from this 
Best Answer chosen by Mayank Deshpande 22
Asif Ali MAsif Ali M
Try the below code to test the functionality of your class. The changes are in your SOQL and the last line. 
 
Public Class ContactSearch{
    List <Contact> Con = New List<Contact>();
    Public List<Contact> searchForContacts (String A, String B){
        Con = [ Select Id , FirstName,LastName from Contact where lastname=:A and MailingPostalCode=:B];
        return (Con);}
}

ContactSearch Contc = New ContactSearch ();
Contc.searchForContacts('Deshpande', 'abcde');

 

All Answers

Asif Ali MAsif Ali M
Try the below code to test the functionality of your class. The changes are in your SOQL and the last line. 
 
Public Class ContactSearch{
    List <Contact> Con = New List<Contact>();
    Public List<Contact> searchForContacts (String A, String B){
        Con = [ Select Id , FirstName,LastName from Contact where lastname=:A and MailingPostalCode=:B];
        return (Con);}
}

ContactSearch Contc = New ContactSearch ();
Contc.searchForContacts('Deshpande', 'abcde');

 
This was selected as the best answer
Mayank Deshpande 22Mayank Deshpande 22
Hi Asif ,

Thanks for reply!!

still not able  to execute the class throug developer consol same error came again .

i declere method in contact serach as static and invoke the method 

Public  Class NewContactSerach {   
    
    ContactSearch.searchForContacts('Deshpande','abcde');
}
Asif Ali MAsif Ali M
I am not 100% sure about salesforce internals but I know that the Classes executed through anonymous block are not saved in DB so referencing the anonymous classes will fail. 

why do you want to have a second class to test the first class? why dont you directly run like below?   
ContactSearch.searchForContacts('Deshpande','abcde');