I'm working on a method to test for FLS. In the Field_Information method in my controller,

Schema.DescribeFieldResult drField = a.Name.getDescribe();

Causes the following error when saving:

Method does not exist or incorrect signature: [String].getDescribe()


Schema.DescribeFieldResult drField = Account.Name.getDescribe();

Saves fine, and allows me to run my test class. I'm new enough to apex but I would like to be able to use the first approach. Can anyone spot the problem or suggest a solution?


public with sharing class FieldLevelSecurityController{

    public FieldLevelSecurityController() {

       Id accountId = ApexPages.currentPage().getParameters().get('AccountId');
       a = [SELECT Name, OwnerId, AccountNumber FROM Account WHERE Id=: accountId];         

    public void Field_Information() {

        Schema.DescribeFieldResult drField = a.Name.getDescribe(); <-- does not work

        Schema.DescribeFieldResult drField = Account.Name.getDescribe(); <-- works

        System.debug(drField.getLabel()); // Similar to VF tag: {!$SObjectType.Account.Fields.Name.Label}


static void getAcc() {

    Account account = new Account(name = 'Test Account');
    insert account;

    ApexPages.currentPage().getParameters().put('AccountId', account.Id);

    FieldLevelSecurityController FLSController = new FieldLevelSecurityController();

    FLSController = new FieldLevelSecurityController(); 

EDIT Maybe I'm wrong, but would a.Name and Account.Name return the same? Since I'm creating the new Account in my test class... Sorry, slightly confused when it comes to apex and testing.


In your example, a is a sObject of type Account containing values for the Account you queried for.

But with Account.Name.getDescribe(), Account is referring to a sObjectType, not a string.

You can use the Id to get the sObjectType using this Id Method if you trying to access the information dynamically. But if you know what the sObject/Fields will be, you can just use the Account.Name.getDescribe() syntax.

| improve this answer | |

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.