2

While saving the below code, following error occurs:

Variable does not exist: DeveloperName

List<Dashboard> listAllDashboards = [SELECT DeveloperName,Type,FolderName,Folder.DeveoperName FROM Dashboard];
for(Dashboard d1 : listAllDashboards){
 System.debug(d1.Folder.DeveloperName);
}
1
  • In your query above you have DeveoperName instead of DeveloperName. Is that how you wrote it in your org or is it a transcription error?
    – Adrian Larson
    Commented Dec 21, 2017 at 18:25

4 Answers 4

2

Folder field on Dashboard object behaves like polymorphic field, that is why before referecing field with dot notation there is a need to cast object to specific type. That means, that the following code works:

List<Dashboard> listAllDashboards = [
    select DeveloperName, Type, FolderName, FolderId, Folder.DeveloperName
    from Dashboard
    ];
for(Dashboard d1 : listAllDashboards){
    System.debug(((Folder)d1.Folder).DeveloperName);
}
2

Weird that we cannot access Folder.DeveloperName directly in Dashboard object.

As an alternative you can do it by Accessing sObject Fields Through Relationships:

for(Dashboard d: [SELECT DeveloperName,Type,FolderName, 
    Folder.DeveloperName FROM Dashboard]) {
    Folder f = d.Folder;
    System.debug('f: ' + f.DeveloperName);
}
1

I think this might be a bug in Salesforce but you can use the sObject method get to retrieve the field by name (there was also a typo on your query):

List<Dashboard> listAllDashboards = [SELECT 
DeveloperName,Type,FolderName,Folder.DeveloperName FROM Dashboard];

for(Dashboard d1 : listAllDashboards){
  System.debug(d1.Folder.get('DeveloperName'));
}
-1
List<Dashboard> listAllDashboards = [SELECT 
DeveloperName,Type,FolderName,Folder.Name FROM Dashboard];
for(Dashboard d1 : listAllDashboards){
System.debug(d1.Folder.Name);
}

Please do something like this

1
  • 1
    -1 as OP wants to access DeveloperName not Name
    – Raul
    Commented Dec 21, 2017 at 10:27

You must log in to answer this question.

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