2

I've checked the other answers and googled alot, cant seem to find the answer to why this doesnt 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 cant find whats wrong..

  • Do you have an object instance in the same class called Account? – BarCotter Jul 23 '14 at 13:02
  • @BarCotter No.. I dont :s I assumed it was being fetched from the standard object Account? – Cammy Jul 23 '14 at 13:52
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.

| improve this answer | |
  • 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! – Cammy Jul 23 '14 at 14:27
4

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()));
    }
}
| improve this answer | |
  • 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? – Cammy Jul 23 '14 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#.. – Cammy Jul 23 '14 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? – Cammy Jul 23 '14 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 Jul 23 '14 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()));
        }
    }
}
| improve this answer | |
  • My issue is that row 2 .getDescribe(); is giving me the error "Method does not exist or incorrect signature: [String].getDescribe()" – Cammy Jul 23 '14 at 14:02

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.