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
Gabe MejiaGabe Mejia 

apex class contactsearch

Wondering if anyone would be able to assist. I am trying to perform a contactsearch that would return the name of a contact(or Salesforce ID) based on a couple cirteria. Any help is appreaciated.

User-added image
Best Answer chosen by Gabe Mejia
Amit Chaudhary 8Amit Chaudhary 8
Code should be like below
 
public class contactsearch{
    public Contact searchContact(String ContactType , String MemberState , String vendorId)
    {
        return [ Select Name From Contact
                  Where Contact_Type__c = 'Vendor Rep' AND States__c =:MemberState AND Vendor__c =:vendorId limit 1
                  ];
    }
}

Let us know if this will work
 

All Answers

Gabe MejiaGabe Mejia
Hopefully this appears a bit clearer.

User-added image
Gabe MejiaGabe Mejia
User-added image
Amit Chaudhary 8Amit Chaudhary 8
Please check below point

1) Do you have Vendor__c field on contact object ?
2) Add return type to Method
3) Change method name.

Please update your code like below

public class contactsearch{
    public Contact searchContact(String ContactType , String MemberState , String vendorId)
    {
        return [ Select Name From Contact
                  Where Contact_Type__c = 'Vendor Rep' AND States__c :MemberState AND Vendor__c :vendorId limit 1
                  ];
    }
}


Let us know if this will help you
 
Gabe MejiaGabe Mejia
I do have Vendor__c on the contact object.

User-added image

I changed the code as suggested and received the following error for line 6:
unexpected token':'

I figured it might be that the '=' was missing just before :MemberState and also just before :vendorId. upon adding the "=' i recieved the original error message about no such column Vendor__c on Contact.
Amit Chaudhary 8Amit Chaudhary 8
Code should be like below
 
public class contactsearch{
    public Contact searchContact(String ContactType , String MemberState , String vendorId)
    {
        return [ Select Name From Contact
                  Where Contact_Type__c = 'Vendor Rep' AND States__c =:MemberState AND Vendor__c =:vendorId limit 1
                  ];
    }
}

Let us know if this will work
 
This was selected as the best answer
Gabe MejiaGabe Mejia
So I figured out why I was still getting the error message for my custom field, Vendor__c. I realized that i had not created the vendor field in the sandbox that i was working out of. Once i refreshed the sandbox, i had access to the vendor field and the code returned without any errors.

Now I just need to find out how to incorperate it with my Visualforce page.

Thank you, Amit.