1

When I changed from the code that's commented out to the current code, the fields from the custom metadata records threw "Variable does not exist" errors. Suggestions on how to correct this?

Relevant Code Snippet

        public void bindServiceTypesAndCapabilities(){
    // List<ServiceOffered__c> servicesList = [Select ID, Services__c, Capabilities__c, Sub_Capabilities__c From ServiceOffered__c];
    List<VRM_Vendor_Services__mdt> servicesList = [SELECT ID, Services__c, Capabilities__c, Sub_Capabilities__c FROM VRM_Vendor_Services__mdt];
    // Above does not like List "Unexpected token'List'" when I try to use List. Removed [] and added List<>
    lstServiceTypes = new List<Selectoption>();                     //Schema.describeDataCategoryGroups(List<String> sobjects)
    Set<String> stService = new Set<String>();
    //for ( ServiceOffered__c svcItem : servicesList ) {
    for ( VRM_Vendor_Services__mdt[] svcItem : servicesList ) {
        if ( !stService.contains(svcItem.Services__c)) {            // adding VRM_Vendor_Services__mdt.Services__c "Can't assign static to sObject fields" 
            lstServiceTypes.add(new selectoption(svcItem.Services__c, svcItem.Services__c));
            stService.add(svcItem.Services__c);
        }
    }

Variable does not exist: Services__c

2 Answers 2

1

Here's the crux:

//for ( ServiceOffered__c svcItem : servicesList ) {
for ( VRM_Vendor_Services__mdt[] svcItem : servicesList ) {

Notice how you went from a single record (ServiceOffered__c) to a collection (VRM_Vendor_Services__mdt[]). Change the loop variable type to VRM_Vendor_Services__mdt. Currently your loop variable is of the type List<...>, and that type does not have any attribute by the name of Services__c.

3
  • WhooHoo! That did it. Commented Mar 22, 2018 at 6:29
  • I have to wait another 17 seconds to accept your answer as the best. Weird rules here :-) Commented Mar 22, 2018 at 6:30
  • @Wade The 15 minute window where you can't accept an answer makes sense in lots of scenarios. Read more about it here. The general SE principle is there might be many good answers, and it should take a minimum amount of time to verify correctness for nontrivial solutions. Often questions and answers on this exchange in particular don't fit that pattern, because there's one obvious thing to fix. But patience to see if better answers roll in is often advised when there is more substance to the question.
    – Adrian Larson
    Commented Mar 22, 2018 at 6:39
1

servicesList variable is type of List class List<VRM_Vendor_Services__mdt> servicesList. So to iterate this collection, change:

for ( VRM_Vendor_Services__mdt[] svcItem : servicesList )

to

for ( VRM_Vendor_Services__mdt svcItem : servicesList )

You must log in to answer this question.

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