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; } }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0