function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce WizardSalesforce Wizard 

Dynamic binding: Error: Invalid field core for SObject Case

So I've been trying to figure out my fieldset and dynamic binding with vf issue.

 

My goal is to have a Map of lists where each lists contains files. I've been experiencing wierd issues.

 

So I attempted to simplify this. Here's what I'm doing.

 

I create my list (lFields) which contains all the field names I'll be using. I have a pageblock section that displays the value of those fields and a second that just lists all the fields.

 

Then I have a map with 2 keys (List1 and List2) each with a list of fields that's a sub-section of lFields. This I loop through on the page. However if I try to put the field in an Output or Input I get this "Invalid Field Core." If I just display {! f} I get the fieldname just fine.

 

Here's my Extension:

public class Admin_FieldSetTest {
    
    public list<string> lFields {get;set;}
    public list<string> lTemps {get;set;}
    public map<string, list<string>> mLists {get;set;}
    public string ConId; 
    private final Case myCase;
    
    public Admin_FieldSetTest(ApexPages.StandardController controller){    
        ConId = controller.getId();
        BuildFieldList();
        controller.addfields(lFields);
        this.mycase = (Case)controller.getrecord(); 
    }
    public void BuildFieldList(){
        //SELECT AccountId,Budget__c,CaseNumber,ContactId,Id,Origin,OwnerId,Physician_List_Format__c,RecordTypeId,Status,Subject FROM Case
        lFields = new list<string>{'AccountId','CaseNumber','Status','Subject','Physician_List_Format__c'};
        ltemps = new list<string>{'AccountId','CaseNumber','Status','Subject','Physician_List_Format__c'};
        mLists = new map<string, list<string>>();
        mLists.put('List1', lTemps);
        ltemps = new list<string>{'Origin', 'OwnerId', 'RecordTypeId','ContactId','Budget__c'};
        mLists.put('List2', lTemps);    
        lFields.add('Origin');lFields.add('OwnerId'); lFields.add('RecordTypeId');lFields.add('ContactId'); lFields.add('Budget__c');   
        for(string s : lFields){
            boolean Matches = false;
            for(string p : mLists.get('List1')){
                if(s.equals(p)){Matches=true;} 
            }
            for(string p : mLists.get('List2')){
                 if(s.equals(p)){Matches=true;}           
            }                
            system.debug('value of: ' + s + ' has a Match: ' + Matches);
            system.assert(Matches,'Match Failure on value: ' + s);
        }
        
    }
}

 And the page:

 

<apex:page standardController="Case" extensions="Admin_FieldSetTest">
<apex:form >
    <apex:pageblock title="The Lists" >
        
        <apex:pageblocksection title="All the Fields" columns="2">
            <apex:repeat value="{!lFields}" var="f">
           <apex:outputfield value="{!Case[f]}" />            
            </apex:repeat>           
        </apex:pageblocksection>
        
    <apex:pageblocksection title="Field List" >
            <apex:repeat value="{!lFields}" var="f">
            {!f}          
            </apex:repeat>           
        </apex:pageblocksection>
        <apex:repeat value="{!mLists}" var="m">
            <apex:pageBlockSection title="{!m}" columns="2">
                <apex:repeat value="{!mLists[m]}" var="f">
                <!-- This Causes my Invalid Field Core Error -->    
                <!-- <apex:outputfield value="{!Case[f]}" /> -->
                    {!f} <!-- This Works just fine -->
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:repeat>
    </apex:pageblock>
    </apex:form>
</apex:page>

 

Output: Output of page

In case the picture doesn't load: http://twitpic.com/9yo0ja

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

In the controller I added this code:

 

  public list<pair> pList {get;set;}

 

 class pair {
       pair(String key, List<String> value) {
          this.key = key;
          this.value = value;
       }
       public String key {get;set; }
       public List<String> value {get; set;}  
    }

 

and right after the code that created the map I added....

 

        plist = new list<pair>();
        for    (string k : mlists.keyset()) {
           plist.add(new pair(k, mlists.get(k)));
        }

 

(you might want to do things differently depending on other requirements of your app...)

 

Then I changed the nested repeat in page to:

 

        <apex:repeat value="{!pList}" var="m">
            <apex:pageBlockSection title="{!m.key}" columns="2">
                <apex:repeat value="{!m.value}" var="f">
                    <!-- This Causes my Invalid Field Core Error -->    
                    <apex:outputfield value="{!Case[f]}" />
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:repeat>

 

I think this is equivalent to what you had with the map....

All Answers

aballardaballard

Is core a custom field?  I don't see it in the lsit of case fields.   If it is custom, you need to use the custom field syntax for the name (core__c)  .

 

Salesforce WizardSalesforce Wizard

That's just it. There is no field called Core.

 

If you look at my field list that I'm hard coding I don't reference anything called Core.

 

I use the same field list in the first pageblock section to get the value of case -- and that works.

 

When I refer to a list that's nested in the map I get the Invalid field Core error...

aballardaballard

ah, sorry, didn't read your code carefullt enough.  That is weird.   I'll see if I can reproduce it....

Salesforce WizardSalesforce Wizard

Appreciated it.

 

I used primarily standard fields in my example so you should be able to Copy and Paste the code and replace the references to Budget__c and Physician_List_Format__c with one of your own fields -- or just delete them:)

 

Just so I am clear. I get the error when I have the apex:outputfield in the apex repeat which is referencing the list stored in the map. I get that before I can save (Dev console) or error when I try to save (straight Page Edit).

 

 

aballardaballard

Ok, it does the same thing for me....  Tried to fidn a workaround but nothing seems to work currently. 

 

Interestingly, if I remove the first repeats (over the list) I get a completely different error (a null pointer exception -- I think the same as someone else reported recently).   I also get the null pointer exception if  I change the var="f" in the second repeat to a different variable name. Doesn't help any, but there is definitely something going wrong here!

 

Salesforce WizardSalesforce Wizard

Ya I was getting the null pointer issue with my project yesterday.

 

This was my attempt to simplify what I was doing just in case it was some crappy code I was writing.

 

Good to know it's not just me! Got any idea what the next step would be to get it looked at?

aballardaballard

Well it is getting looked at :-) but if you have access to Salesforce support you should probably open a case which will help get it fixed sooner.   You can tell support to link your case to bug W-1300416 .

 

Unfortunately a fix is not likely to be delivered really quickly... I'm looking to see what might work instead....

aballardaballard

Your best bet for working around this for now is probably to replace the map with a list of  (key,  value) objects.   I did a quick test of this and the nested repeat seemed to work ok for that.  (I defined a class pair with properties key and  value, creates a list<pair> from the keys and values in your map, then made the appropriate changes to the nested repeat to iterate over this list instead. 

 

 

sivaextsivaext

Hi 

 

you can try in this way

 

 <apex:repeat value="{!mLists}" var="f">
                <!-- This Causes my Invalid Field Core Error -->    
                <!-- <apex:outputfield value="{!Case[f]}" /> -->
                    {!mLists[f]} <!-- This Works just fine -->
                </apex:repeat>
sivaextsivaext

Hi 

 

for this each field

 

 <apex:repeat value="{!mLists}" var="f">
                <!-- This Causes my Invalid Field Core Error -->    
                <!-- <apex:outputfield value="{!Case[f]}" /> -->
                    {!mLists[f].fieldname} <!-- This Works just fine -->
                </apex:repeat>
Salesforce WizardSalesforce Wizard

That just went over my head a bit. Do you have a simple example of what you did for the Key, value object?

Salesforce WizardSalesforce Wizard

sivaext,

 

Thanks for your reply. I get an error on the page with both of your suggestions. Visualforce tells me I have an error in the expression.

aballardaballard

In the controller I added this code:

 

  public list<pair> pList {get;set;}

 

 class pair {
       pair(String key, List<String> value) {
          this.key = key;
          this.value = value;
       }
       public String key {get;set; }
       public List<String> value {get; set;}  
    }

 

and right after the code that created the map I added....

 

        plist = new list<pair>();
        for    (string k : mlists.keyset()) {
           plist.add(new pair(k, mlists.get(k)));
        }

 

(you might want to do things differently depending on other requirements of your app...)

 

Then I changed the nested repeat in page to:

 

        <apex:repeat value="{!pList}" var="m">
            <apex:pageBlockSection title="{!m.key}" columns="2">
                <apex:repeat value="{!m.value}" var="f">
                    <!-- This Causes my Invalid Field Core Error -->    
                    <apex:outputfield value="{!Case[f]}" />
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:repeat>

 

I think this is equivalent to what you had with the map....

This was selected as the best answer
Salesforce WizardSalesforce Wizard

Okay, very nifty. 

 

Is that also considered a Wrapper/helper class? 

 

I'll give it a try today and see if it works with what I"m doing. I'll update here with a confirmation. Thanks!

Salesforce WizardSalesforce Wizard

Awesome!

 

That works like a charm!

 

I wonder why wrapping it in a class gives a different result than the map? It's looks specific to the  outputfield and inputfield components since I don't get the error if I just reference {!Case[f]} with no component.

 

Thank you again. Now I can make my page uber awesome.

sduvvurisduvvuri
Hi,
I got the same error when I have two apex repeats in my page
<!-- Begning of Promotion Details -->
            <apex:pageBlockSection title="Promotion Details">
                <apex:repeat value="{!requiredFields}" var="f">
                    <apex:inputField value="{!prom[f.fieldPath]}" required="true"/>
                </apex:repeat>

            </apex:pageBlockSection>
            <!-- End of Promotion Details -->
<!-- Channel details -->
            <apex:repeat value="{!availableChannels}"
                     var="c">

              <apex:pageBlockSection collapsible="false"
                                      columns="2"
                                      id="channel_detail_section"
                                      title="{!c.strValue}"
                                      rendered="{!c.isSelected}">

                  <apex:pageBlockSectionItem id="channelHelpText" helpText="{!$ObjectType.Promotion__c.Fields.Channel__c.inlineHelpText}">
                      <apex:outputLabel value="{!$ObjectType.Promotion__c.Fields.Channel__c.label}" />
                      <apex:outputField value="{!c.promoRec.Channel__c}" id="channelValueField"/>
                  </apex:pageBlockSectionItem>

                   <apex:repeat value="{!channelFieldsMap[c.strMapkey]}" var="f">
                        <apex:pageBlockSectionItem helpText="{!$ObjectType.Promotion__c.Fields[f.fieldPath].inlineHelpText}">
                            <apex:outputLabel value="{!$ObjectType.Promotion__c.fields[f.fieldPath].label}" />
                              <apex:outPutField value="{!c.promoRec[f.fieldPath]}"/>
                          </apex:pageBlockSectionItem>
                      </apex:repeat>
              </apex:pageBlockSection>

          </apex:repeat>

Have two different <apex:repeats iterating over different collections but I used same var "f".

I fixed this issue by changing the variable name in one <apex:repeat
<apex:repeat value="{!availableChannels}"
                     var="c">

              <apex:pageBlockSection collapsible="false"
                                      columns="2"
                                      id="channel_detail_section"
                                      title="{!c.strValue}"
                                      rendered="{!c.isSelected}">

                  <apex:pageBlockSectionItem id="channelHelpText" helpText="{!$ObjectType.Promotion__c.Fields.Channel__c.inlineHelpText}">
                      <apex:outputLabel value="{!$ObjectType.Promotion__c.Fields.Channel__c.label}" />
                      <apex:outputField value="{!c.promoRec.Channel__c}" id="channelValueField"/>
                  </apex:pageBlockSectionItem>

                   <apex:repeat value="{!channelFieldsMap[c.strMapkey]}" var="fs">
                        <apex:pageBlockSectionItem helpText="{!$ObjectType.Promotion__c.Fields[fs.fieldPath].inlineHelpText}">
                            <apex:outputLabel value="{!$ObjectType.Promotion__c.fields[fs.fieldPath].label}" />
                              <apex:outPutField value="{!c.promoRec[fs.fieldPath]}"/>
                          </apex:pageBlockSectionItem>
                      </apex:repeat>
              </apex:pageBlockSection>

          </apex:repeat>