1

I have a object Competitor_Mapping__c that has lookup with Account. In the page, i have used standard controller of Account to fetch the current Account id from URL, used in a SOQL to populate a list of associated Competitor_Mapping__c records, within an extension, which errors out Error: Invalid field Competitor_Product__c for SObject Account Competitor_Product__c is a field of Competitor_Mapping__c.

Here is the code :

<apex:page StandardController="Account" extensions="inline1"  id="thePage"> 
    <apex:form id="theForm"> 
      <apex:pageBlock id="thePageBlock"> 
            <apex:pageBlockTable value="{!records}" var="record" id="thePageBlockTable"> 
                 <apex:column width="25" style="background:pink;">
                    <apex:inputField value="{!record.Competitor_Product__c}" id="AccountTypeDOM"/>

                    <apex:facet name="header">CompetitorProduct</apex:facet>
                </apex:column>


                 <apex:column style="background: lightgreen;" >
                    <apex:outputField value="{!record.January__c}" id="January" > 
                <apex:inlineEditSupport event="ondblClick"  showOnEdit="saveButton" hideOnEdit="AddMoreButton"
                       /> 
                       </apex:outputfield>
                    <apex:facet name="header">January</apex:facet>
                </apex:column>
               <apex:column style="background:lightgreen;" >
                    <apex:outputField value="{!record.February__c}" id="February" >
                    <apex:inlineEditSupport event="ondblClick"  showOnEdit="saveButton" hideOnEdit="AddMoreButton"
                       /> 
                       </apex:outputfield>  
                    <apex:facet name="header">February</apex:facet>
                </apex:column>
           </apex:pageBlockTable> 
            <apex:pageBlockButtons > 

                <apex:commandButton value="Save" action="{!save}"   id="saveButton" />
                <apex:commandButton value="Add More" action="{!AddMore}" id="AddMoreButton" />
            </apex:pageBlockButtons> 
        </apex:pageBlock>   
    </apex:form>
</apex:page>

Here is the controller code :

public class inline1{

public List<Competitor_Mapping__c> records=new List<Competitor_Mapping__c>();
//public Map<ID, List<Competitor_Mapping__c>> records = new Map<ID, List<Competitor_Mapping__c>>();

//public List<Competitor_Mapping__c> records= [select id,Competitor_Product__c,January__c,February__c,March__c,April__c,May__c,June__c,July__c,August__c,September__c,October__c,November__c,December__c from Competitor_Mapping__c];
public List<Competitor_Mapping__c>lstAcct  = new List<Competitor_Mapping__c>();
public Boolean b{get;set;}
public Id Acc_Id {get;set;}

public List<Competitor_Mapping__c> getrecords()
{


return records;
}
/*Constructor*/
    public void inline1()
    {  

    }/*End Constructor*/

/*Constructor*/
    public inline1(ApexPages.StandardController controller)
    {  

   records= [select id,Competitor_Product__c,January__c,February__c,March__c,April__c,May__c,June__c,July__c,August__c,September__c,October__c,November__c,December__c from Competitor_Mapping__c where Account__c=:ApexPages.currentPage().getParameters().get('id')];
    }
   /*End Constructor*/
  public PageReference Save()
    {
        PageReference pr = new PageReference('/apex/inline1');

        for(Integer j = 0;j<records.size();j++)
        {
            lstAcct.add(records[j]);
        } 
        Update lstAcct;
        pr.setRedirect(True);
        return pr;
    }

    public PageReference AddMore()
    {
        PageReference pr = new PageReference('/apex/inline1');

        Competitor_Mapping__c newRec=new Competitor_Mapping__c ();
        Insert newRec;
        pr.setRedirect(True);
        return pr;
    }

   public PageReference Del()
    {
        PageReference pr = new PageReference('/apex/inline1');
         pr.setRedirect(True);
        return pr;
    }
}
  • When do you get this error? while loading the page or while hitting Save button? Please add debug log to find the location/line number where it breaks – Vignex Dec 15 '14 at 9:27
3

The problem is that the Visualforce page compiler assumes the "record" in {!record.Competitor_Product__c} is the return value of the getRecord method of the standard controller rather than the var="record" of the apex:pageBlockTable. Hence the field name is looked for in Account not Competitor_Mapping__c.

(At runtime the opposite occurs: if a field that appears in both objects is used, the var="record" reference wins.)

Change the name you use in var="record" to some other name to fix.

| 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.