1

Please help me figure out a way on how to solve this. The below query gives me error :

Error: Compile Error: Didn't understand relationship 'contactData' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 18 column 27

    displayContacts = [select id,
                       Name,
                       Domain__c,
                       City__c,
                       FirstName,
                       LastName,
                       Email,
                       Country__c from Contact where 
                       (Domain__c=:contactData.Domain__c OR contactData.Domain__c==NULL)
                       AND (City__c=:contactData.City__c OR contactData.City__c == NULL)
                       AND (Country__c=:contactData.Country__c OR contactData.Country__c == NULL];   

I am trying to use the value generated from Visualforce page to add condition in the query. enter image description here

myClass

class getpicklstval1{

public String searchString {get;set;}
public Boolean allContacts{get;set;}   
public Contact ContactData{get;set;}
public List<Contact> displayContacts{get;set;}
public getpicklstval1(ApexPages.StandardController controller){
    ContactData = new Contact();
    displayContacts = new List<Contact>();       
}

public void called(){
    if(contactData.Domain__c!=NULL && contactData.City__c!=NULL && contactData.Country__c!=NULL){
    displayContacts = [select id,
                       Name,
                       Domain__c,
                       City__c,
                       FirstName,
                       LastName,
                       Email,
                       Country__c from Contact where 
                       (Domain__c=:contactData.Domain__c OR contactData.Domain__c==NULL)
                       AND (City__c=:contactData.City__c OR contactData.City__c == NULL)
                       AND (Country__c=:contactData.Country__c OR contactData.Country__c == NULL];                           
   }                
}

public List<Contact> getreturnContact(){
    return displayContacts;
}
public void SearchKeyword(){
}    }  

Visualforce Page

    <apex:page StandardController="Contact" extensions="getpicklstval1">
    <apex:form >
    <apex:inputField id="Domain" value="{!ContactData.Domain__c}" style="width:159px;">
        <apex:actionSupport event="onchange" action="{!called}" rerender="displayContacts"/>
    </apex:inputfield>  
    <apex:inputField id="City" value="{!ContactData.City__c}" style="width:159px;">
        <apex:actionSupport event="onchange" action="{!called}" rerender="displayContacts"/>
    </apex:inputfield>    
    <apex:inputField id="Country" value="{!ContactData.Country__c}" style="width:159px;">
        <apex:actionSupport event="onchange" action="{!called}" rerender="displayContacts"/>
    </apex:inputfield>    

    <apex:pageBlock id="displayContacts">
    <apex:pageblockTable id="searchContactList" var="contact" value="{!returnContact}">     

         <apex:column style="width:3px;">
                 <apex:facet name="header"/>                  
                         <apex:inputCheckbox value="{!contact.Name}" id="checkedone" style="width:15px;">                 
                 </apex:inputCheckbox>                 
         </apex:column>
         <apex:column style="width:200px; height:60px;">
            <apex:facet name="header">
                <apex:outputPanel layout="block" style="text-align:center;">
                     First Name
                </apex:outputPanel>                    
            </apex:facet>                   
            <apex:outputLink value="/{!contact.id}">{!contact.FirstName}</apex:outputLink>               
         </apex:column>                      
         </apex:pageblockTable>
        </apex:pageBlock> 
    </apex:form>
    </apex:page>
1

You will want to use dynamic soql because then you can choose which things to query for depending if you user selects them. Try this.

String displayContactsStr = 'select id, Name, Domain__c, City__c, FirstName, LastName, Email, Country__c from Contact where Name <> null '; 
if (contactData.Domain__c != '') {
   displayContactsStr += ' and Domain__c = \'' + contactData.Domain__c +  '\'';
}
if (contactData.Country__c != '') {
   displayContactsStr += ' and Country__c = \'' + contactData.Country__c +  '\'';
}
if (contactData.City__c != '') {
   displayContactsStr += ' and City__c = \'' + contactData.City__c +  '\'';
}
displayContacts = (List<Contact>)Database.query(displayContactsStr);
  • Hi @CyberJus - I have tried your query. It gives me following error : Error: Compile Error: unexpected token: ':' at line 22 column 56 Please check the screen shot here : snag.gy/i90Gr.jpg – Jayati Jaiswal Mar 29 '15 at 12:25
  • I updated the solution. I didnt really check the rest of it, just put in the : to your query. You were missing a ) and you only need one = in soql – CyberJus Mar 29 '15 at 12:58
  • Wow, it is early. I understand what you want to do. I will edit the solution. – CyberJus Mar 29 '15 at 13:01
  • Hi @CyberJus - I have tried all possible ways .. Please check the screen shot with only one = snag.gy/MK0s5.jpg – Jayati Jaiswal Mar 29 '15 at 13:01
  • Sorry, I updated the solution. I should have read it better the first time. – CyberJus Mar 29 '15 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.