You need to sign in to do that
Don't have an account?
SeanCeno
Visual Force Controller: Method Does Not Exist or Incorrect Signature
I haven't dealt with writing code for Visualforce pages yet. We have a search function for contacts that allows you to search by Zipcode and City. We want to add the ability to search by State and by contact Owner. I have adjusted most of the code so far, but I'm getting a
Line 84: "Method Does Not Exist or Incorrect Signature: getContactsByState(LIST<String>)" error.
Do I have to define this method in the visualforce page as well with a Script? If code is needed:
public with sharing class TerritorySearchController { public String searchType { public get; public set; } public String searchValue { public get; public set; } public String zipcode { public get; public set; } public String contactType { public get; public set; } //Contact_Type__c public String statusType { public get; public set; } //Producer_Status__c / Prospect_Status__c public String citySearch { public get; public set; } public String citySearchResults { public get; public set; } public String citySearchSelected { public get; public set; } public String stateSearch { public get; public set; } public String stateSearchResults { public get; public set; } public String stateSearchSelected { public get; public set; } public String ownerSearch { public get; public set; } public String ownerSearchResults { public get; public set; } public String ownerSearchSelected { public get; public set; } public List<Contact> reps { public get; private set; } public List<Contact> repl {public get; private set; } public List<Contact> repo {public get; private set; } public Boolean mapView { public get; private set; } public TerritorySearchController() { this.reps=new List<Contact>(); this.searchType = getParam('searchType', 'zipcode'); this.searchValue = getParam('searchValue', ''); this.zipcode = getParam('zipcode', ''); this.contactType = getParam('contactType', ''); this.statusType = getParam('statusType', ''); this.citySearch = getParam('citySearch', ''); this.citySearchResults = ''; this.citySearchSelected = ''; this.stateSearch = getParam('stateSearch', ''); this.stateSearchResults = ''; this.stateSearchSelected = ''; this.ownerSearch = getParam('ownerSearch', ''); this.ownerSearchResults = ''; this.ownerSearchSelected = ''; this.mapView = getBooleanParam('mapView', false); } public String getParam(String name, String defaultValue) { String value = ApexPages.currentPage().getParameters().get(name); return value == null ? defaultValue : value; } public Boolean getBooleanParam(String name, Boolean defaultValue) { String value = ApexPages.currentPage().getParameters().get(name); return value == null ? defaultValue : 'true'.equalsIgnoreCase(value); } public PageReference processSearch() { PageReference p=null; if (this.searchType=='city') p=searchCities(); else if(this.searchType=='state') p=searchStates(); else if(this.searchType=='zipcode') p=searchZips(); else if(this.searchType=='owner') p=searchOwners(); return p; } public PageReference searchZips() { List<String > lZips=new List<String>(); lZips.add(this.searchValue); this.reps=getContactsByZip(lZips); return null; } public PageReference searchStates() { List<String> lStates=new List<String>(); lStates.add(this.searchValue); this.reps=getContactsByState(lStates); return null; } public PageReference searchOwners() { List<String > lOwners=new List<String>(); lOwners.add(this.searchValue); this.reps=getContactsByOwner(lOwners); return null; } public PageReference searchForCities() { String str=''; this.citySearchResults='['; String strCity=this.citySearch; //Apexpages.currentPage().getParameters().get('citySearch'); String strSOQL='SELECT Id, Name, City__c, State__c FROM Zip_Codes__c WHERE City__c LIKE \''+strCity+'%\' ORDER BY State__c LIMIT 10'; System.debug(strSOQL); List<Zip_Codes__c> lZ=Database.query(strSOQL); Set<String> sZ=new Set<String>(); for(Zip_Codes__c z : lZ) { str=z.City__c+', '+z.State__c; if(!sZ.contains(str)) { if(sZ.size()>0) this.citySearchResults=this.citySearchResults+','; this.citySearchResults=this.citySearchResults+' { value: \''+z.Id+'\', label: \''+str.replace('\'', '\\\'')+'\'} '; sZ.add(str); } } this.citySearchResults=this.citySearchResults+']'; return null; } public PageReference searchCities() { this.reps=getContactsByCity(this.searchValue); return null; } public PageReference searchForStates() { String str=''; this.stateSearchResults='['; String strState=this.stateSearch; //Apexpages.currentPage().getParameters().get('stateSearch'); String strSOQL='SELECT Id, Name, City__c, State__c FROM Zip_Codes__c WHERE State__c LIKE \''+strState+'%\' ORDER BY City__c LIMIT 10'; System.debug(strSOQL); List<Zip_Codes__c> lS=Database.query(strSOQL); Set<String> sS=new Set<String>(); for(Zip_Codes__c s : ls) { str=s.City__c+', '+s.State__c; if(!stS.contains(str)) { if(stS.size()>0) this.stateSearchResults=this.stateSearchResults+','; this.stateSearchResults=this.stateSearchResults+' { value: \''+s.Id+'\', label: \''+str.replace('\'', '\\\'')+'\'} '; stS.add(str); } } this.stateSearchResults=this.stateSearchResults+']'; return null; } public PageReference searchForOwners() { String str=''; this.ownerSearchResults='['; String strOwner=this.ownerSearch; //Apexpages.currentPage().getParameters().get('ownerSearch'); String strSOQL='SELECT Id, Name, City__c, State__c FROM Zip_Codes__c WHERE Owner__c LIKE \''+strOwner+'%\' ORDER BY Owner__c LIMIT 10'; System.debug(strSOQL); List<Zip_Codes__c> lO=Database.query(strSOQL); Set<String> sO=new Set<String>(); for(Zip_Codes__c o : lO) { str=o.City__c+', '+o.State__c+', '+o.Owner__c; if(!sO.contains(str)) { if(sO.size()>0) this.ownerSearchResults=this.ownerSearchResults+','; this.ownerSearchResults=this.ownerSearchResults+' { value: \''+o.Id+'\', label: \''+str.replace('\'', '\\\'')+'\'} '; sO.add(str); } } this.ownerSearchResults=this.ownerSearchResults+']'; return null; } public Integer getRepCount() { return this.reps.size(); } private List<Contact> getContactsByZip(List<String> lZips) { List<Contact> lContacts=new List<Contact>(); if(contactType==null) contactType=''; String strZipCodes=' \'0\''; String strSOQL='SELECT ID, Name, MailingStreet, MailingCity, MailingState, MailingPostalCode, MailingCountry, Phone, Email, Contact_Type__c, Prospect_Status__c, Producer_Status__c, Broker_Dealer_Name__c FROM Contact '; for(String s: lZips) { if(s.trim()!='') { strZipCodes=strZipCodes+' OR mailingpostalcode like \''+s+'%\' '; this.zipcode=s; } } strSOQL=strSOQL+' WHERE (MailingPostalCode like' + strZipCodes + ') '; //strSOQL=strSOQL+' AND SA_Status__c = \'NS REIT - Signed Selling Agreement\' '; strSOQL=strSOQL+' AND ( NS_Income_II_SA_Status__c = \'NS I2 - Signed Selling Agreement\' OR NS_HI_SA_Status__c = \'NS HI - Signed Selling Agreement\' )'; strSOQL=strSOQL+' AND Contact_Type__c != \'POND List\' '; strSOQL=strSOQL+' AND Contact_Type__c != null '; strSOQL=strSOQL+' AND OWNER__c !=null '; // // Handle producer/prospect types. // if ('Un-Profiled'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Un-Profiled\' '; } else if ('All Producers'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Producer\''; } else if ('A Producers'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Producer\' AND Producer_Status__c like \'Producer A-%\''; } else if ('B Producers'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Producer\' AND Producer_Status__c like \'Producer B-%\''; } else if ('C Producers'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Producer\' AND Producer_Status__c like \'Producer C-%\''; } else if ('Sphere Of Influence Producers'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Producer\' AND Producer_Status__c like \'Sphere of Influence%\''; } else if ('All Prospects'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Prospect\''; } else if ('A Prospects'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Prospect\' AND Prospect_Status__c like \'Prospect A-%\''; } else if ('B Prospects'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Prospect\' AND Prospect_Status__c like \'Prospect B-%\''; } else if ('C Prospects'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Prospect\' AND Prospect_Status__c like \'Prospect C-%\''; } else if ('Sphere Of Influence Prospects'.equalsIgnoreCase(contactType)) { strSOQL += ' AND Contact_Type__c = \'Prospect\' AND Prospect_Status__c like \'Sphere of Influence%\''; } System.debug(strSOQL); lContacts=Database.query(strSOQL); return lContacts; } private List<Contact> getContactsByCity(String strCityState) { List<Contact> lContacts=new List<Contact>(); Integer i=strCityState.lastIndexOf(','); if(i<1) return lContacts; String strCity=strCityState.substring(0, i).trim(); String strState=strCityState.substring(i+1).trim().toUpperCase(); System.debug('SELECT Id,Name FROM Zip_Codes__c WHERE City__c =\''+strCity+'\' AND State__c=\''+strState+'\' ORDER BY longitude__c'); List<Zip_Codes__c> lZ=[SELECT Id,Name FROM Zip_Codes__c WHERE City__c=:strCity AND State__c=:strState ORDER BY longitude__c]; List<String> lZips=new List<String>(); for(Zip_Codes__c z : lZ) { lZips.add(z.Name); } lContacts=getContactsByZip(lZips); return lContacts; } private List<Contact> getContactsByState(String strCityState) { list<Contact> llContacts=new List<Contact>(); Integer i=strCityState.lastIndexOf(','); if(i<1) return llContacts; String strCity=strCityState.substring(0, i).trim(); String strState=strCityState.substring(i+1).trim().toUpperCase(); System.debug('SELECT Id,Name FROM Zip_Codes__c WHERE City__c =\''+strCity+'\' AND State__c=\''+strState+'\' ORDER BY longitude__c'); List<Zip_Codes__c> lS=[SELECT Id, Name, City__c, State__c FROM Zip_Codes__c WHERE City__c=:strCity AND State__c=:strState ORDER BY City__c LIMIT 10]; List<String> lStates=new List<String>(); for(Zip_Codes__c s : lS) { lStates.add(s.Name); } llContacts=getContactsByState(lStates); return llContacts; } private List<Contact> getContactsByOwner(String strOwner) { List<Contact> lllContacts=new List<Contact>(); List<Zip_Codes__c> lO=[select Id, Name, longitude__c, latitude__c, Territory__c, Owner__c, City__c, State__c from Zip_Codes__c WHERE Owner__r.Name=:strOwner]; List<String> lOwners=new List<String>(); for(Zip_Codes__c o : lO) { lOwners.add(o.Name); } lllContacts=getContactsByOwner(lOwners); return lllContacts; } public Boolean getIsDisabledDownloadCSV() { return reps == null || reps.size() == 0; } public PageReference redirectToCSV() { processSearch(); String documentData = ''; documentData += '"Name",'; documentData += '"Broker_Dealer_Name__c",'; documentData += '"MailingStreet",'; documentData += '"MailingCity",'; documentData += '"MailingState",'; documentData += '"MailingPostalCode",'; documentData += '"Phone",'; documentData += '"Email",'; documentData += '"Last Completed Event",'; documentData += '"Contact_Type__c"\r\n'; for(Contact contact : reps) { documentData += '"' + contact.Name + '",'; documentData += '"' + contact.Broker_Dealer_Name__c + '",'; documentData += '"' + contact.MailingStreet + '",'; documentData += '"' + contact.MailingCity + '",'; documentData += '"' + contact.MailingState + '",'; documentData += '"' + contact.MailingPostalCode + '",'; documentData += '"' + contact.Phone + '",'; documentData += '"' + contact.Email + '",'; documentData += '"' + contact.Last_Event_Date__c + '",'; documentData += '"' + contact.Contact_Type__c + '"\r\n'; } Document document = new Document(); document.Body = Blob.valueOf(documentData); document.ContentType = 'text/csv'; document.FolderId = UserInfo.getUserId(); document.Name = 'Territory Search - CSV Export - ' + DateTime.now().format() + '.csv'; insert document; PageReference pageReference = new PageReference('/servlet/servlet.FileDownload?file=' + document.Id); pageReference.setRedirect(true); return pageReference; } public String getMapViewUrl() { PageReference pageReference = System.Page.TerritorySearch; pageReference.getParameters().put('searchType', searchType); pageReference.getParameters().put('searchValue', searchValue); pageReference.getParameters().put('zipcode', zipcode); pageReference.getParameters().put('contactType', contactType); pageReference.getParameters().put('statusType', statusType); pageReference.getParameters().put('citySearch', citySearch); pageReference.getParameters().put('stateSearch', stateSearch); pageReference.getParameters().put('ownerSearch', ownerSearch); pageReference.getParameters().put('mapView', 'true'); return pageReference.getUrl(); } }
The "Incorrect Signature" part of the message is the problem. The getContactsByState() method is defined to receive a String param, but the param that you are sending it, lStates, is a List of Strings.
All Answers
The "Incorrect Signature" part of the message is the problem. The getContactsByState() method is defined to receive a String param, but the param that you are sending it, lStates, is a List of Strings.
Thank you! Was forgetting:
private List<contact> getContactsByState (List<String> lStates)