2

Error Error: Autocompletefields Compile Error: Method does not exist or incorrect signature: [Id].contains(String) at line 20 column 21

public class Autocompletefields {
     public AutoCompletefields(ApexPages.StandardSetController controller) {
        }
       //Variable declaration
       transient public String[] jsonDescriptionData;
       //Constructor with argument as standrad controller
        public AutoCompletefields(ApexPages.StandardController controller) { }
        //Simple construcor
        public AutoCompletefields(){}
        //Method to return all nicopin for France user
        public List<string> getjsonDescriptionData(){
            jsonDescriptionData = new List<string>();
                //List of nicopin for france
                List<Quote__c> francePinCodeList=[SELECT Account_name__c FROM Quote__c LIMIT 50000];
                //Set to get all nico pin as string
                Set<String> pncodeSet=new Set<String>();
                 String quoteStr='"';
                //Iterate to collect set of all nico pin
                for(Quote__c cpnCod : francePinCodeList){
                    if(!cpnCod.Account_name__c.contains(quoteStr)){
                        pncodeSet.add(cpnCod.Account_name__c);
                    }//End of if
                }//End of for loop
                //Iterate to collect all pin in string format
                for(String str:pncodeSet){
                    jsonDescriptionData.add('"'+str+'"');
                }
                //To sort the nicopin list
               jsonDescriptionData.sort();
                return jsonDescriptionData;
        }//End of method

    }

can anybody correct this error ?

1 Answer 1

3

Id objects don't contain all the same methods as String objects. Cast one into the other first.

You could change your example to ((String)cpnCod.Account_name__c).contains(quoteStr)

2
  • if(!(((String)cpnCod.Account_name__c).contains(quoteStr))){
    – Teja
    Commented Dec 20, 2013 at 8:41
  • I am getting the error System.NullPointerException: Attempt to de-reference a null object line 20 column 1
    – Teja
    Commented Dec 20, 2013 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .