2

I've checked the other answers and googled a lot, can't seem to find the answer to why this doesn't work:

public List<SelectOption> AccountIndustryOptions = new List<SelectOption>();
public List<SelectOption> getAccountIndustryOptions(){
    if(AccountIndustryOptions == null){
        setAccountIndustryOptions();
    }
    return AccountIndustryOptions;
}

public void setAccountIndustryOptions(){
    Schema.DescribeFieldResult industry = Account.Industry.getDescribe();

    List<Schema.PicklistEntry> P = industry.getPicklistValues();
    
    AccountIndustryOptions.add(new SelectOption('All','All'));
    
    for(Schema.PicklistEntry i : P)
    {
        if(P[i].isActive())
        {
            AccountIndustryOptions.add(new SelectOption(P[i].getLabel(),P[i].getLabel()));
        }
    }
}

I get error "Method does not exist or incorrect signature: [String].getDescribe()" for line 2 I can't find what's wrong.

2
  • Do you have an object instance in the same class called Account?
    – BarCotter
    Commented Jul 23, 2014 at 13:02
  • @BarCotter No.. I dont :s I assumed it was being fetched from the standard object Account?
    – Camathon
    Commented Jul 23, 2014 at 13:52

3 Answers 3

3

Another way of avoiding this problem of the account SObject variable hiding the Account SObjectType (as Apex is case insensitive) is to qualify the Account SObjectType reference like this:

DescribeFieldResult industry = Schema.Account.Industry.getDescribe();

This avoids having to change other existing code.

1
  • Amazing this actually compiles! I was trying something with schema before of what I found on this link developer.salesforce.com/forums/… but I didnt understand that I should have replaced the sObject with Account.. Basic newbie errors. Thanks alot!
    – Camathon
    Commented Jul 23, 2014 at 14:27
5

Having a SObject instance called account will cause this error. See the example below:

Account account = [Select Id, Industry from Account limit:1];
Schema.DescribeFieldResult industry = Account.Industry.getDescribe();

The above code throws the error Method does not exist or incorrect signature: [String].getDescribe() because Account.Industry now resolves to the Industry field on the account record, which is a string. Try rename your reference to account to something like selectedAccount or currentAccount


Another issue in your code is the for loop. i is the instance of your PicklistEntry so you don't need to use P[i]. Your code should look something like this (I've renamed the variables to make it clearer):

List<Schema.PicklistEntry> picklistValues = industry.getPicklistValues();
accountIndustryOptions.add(new SelectOption('All','All'));
for (Schema.PicklistEntry picklistValue : picklistValues) {
    if (picklistValue.isActive()) {
        accountIndustryOptions.add(new SelectOption(picklistValue.getLabel(), picklistValue.getLabel()));
    }
}
4
  • Strange, I'm trying to refactor some parts of this old salesforce app called Findnearby. Check row 503 here pastebin.com/D05HzR4T they have no other referance to the Account object (That I can see), so how did THAT code ever work?
    – Camathon
    Commented Jul 23, 2014 at 13:55
  • Thanks for sorting out my for loop. I'm really terrible at apex coding since I'm mainly a front end developer and just have basic knowledge about C#..
    – Camathon
    Commented Jul 23, 2014 at 13:56
  • "rename your reference to account to something like selectedAccount or currentAccount", by renaming the variable how would that change Industry from being a string?
    – Camathon
    Commented Jul 23, 2014 at 14:06
  • If you cant find the reference then try changing the line to Schema.Account.Industry.getDescribe();, which will let SF know that you are referring to a field on the Account object
    – BarCotter
    Commented Jul 23, 2014 at 14:13
-1

Just Change the method

public void setAccountIndustryOptions(){
    Schema.DescribeFieldResult industry = Account.Industry.getDescribe();

    List<Schema.PicklistEntry> P = industry.getPicklistValues();

    AccountIndustryOptions.add(new SelectOption('All','All'));

    for(Schema.PicklistEntry i : P)
    {
        if(i.isActive())
        {
            AccountIndustryOptions.add(new SelectOption(i.getLabel(),i.getLabel()));
        }
    }
}
1
  • My issue is that row 2 .getDescribe(); is giving me the error "Method does not exist or incorrect signature: [String].getDescribe()"
    – Camathon
    Commented Jul 23, 2014 at 14:02

You must log in to answer this question.

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