whats wrong in this code(Error: Invalid field ischecked for SObject Sample_Item__c )

I dont know whats wrong in this code im getting this error msg but im not getting the records

Error: Invalid field ischecked for SObject Sample_Item__c

class

public with sharing class sampleitem {

public PageReference doSelect() {
    List<sample_Item__c> lstswi = new List<sample_Item__c>();
    for(wrapperSample objws : lstWS){
        if(objws.ischecked == true){
            objws.swi.Item__c = pid;
            update objws.swi;
        }

    }
    return (new pagereference('/'+pid).setredirect(true));
}

public String pId = apexpages.currentpage().getparameters().get('pid');
public String wtId = apexpages.currentpage().getparameters().get('wid');
public List<sample_Item__c> lstSWI{get;set;}
public wrapperSample objWS{get;set;}
public List<wrapperSample> lstWS{get;set;}
public sampleitem(){
    lstSWI = new List<sample_Item__c>();
    lstSWI = new List<sample_Item__c>();
    lstSWI = [select id,name,Stage__r.Name,Item__r.name from sample_Item__c where Template__c =: wtId];
    lstWS = new List<wrapperSample>();
    for(sample_Item__c objSWI : lstSWI){
        objWS = new wrapperSample();
        objWS.swi = objSWI;
        lstWS.add(objWS);
    }
}

public class wrapperSample{
    public sample_Item__c swi{get;set;}
    public boolean ischecked{get;set;}
}

page

<apex:page controller="sampleitem">
  <apex:form >
      <apex:pageblock >
          <apex:pageblocksection >
              <apex:pageblocktable value="{!lstWS}" var="S">
                  <apex:column headerValue="Select">
                      <apex:inputcheckbox value="{!S.ischecked}"/>
                  </apex:column>
                  <apex:column headerValue="Name">
                      <apex:outputtext value="{!S.swi.Name}"></apex:outputtext>
                  </apex:column>
                   <apex:column headerValue="Stage">
                      <apex:outputtext value="{!S.swi.Stage__r.Name}"></apex:outputtext>
                  </apex:column>
                  <apex:column headerValue="Item Name">
                      <apex:outputtext value="{!S.swi.Item__r.name}"></apex:outputtext>
                  </apex:column>
              </apex:pageblocktable>
          </apex:pageblocksection>
          <apex:commandButton value="Select" Action="{!doSelect}"/>
      </apex:pageblock>
  </apex:form>

![enter image description here][1]

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

Having switched in another test custom object of my own into your sample, this appears to compile and run fine for me? Stupid quesiton I know, but are you sure your controller is upto date with the server?

I guess the other difference between mine and yours is I removed the last two columns (since my test object didn’t have those columns). However I don’t see that making a difference. Anyway here is what I have and it works just fine…

public with sharing class sampleitem {

public PageReference doSelect() {
    List<test__c> lstswi = new List<test__c>();
    for(wrapperSample objws : lstWS){
        if(objws.ischecked == true){
            update objws.swi;
        }

    }
    return (new pagereference('/'+pid).setredirect(true));
}

public String pId = apexpages.currentpage().getparameters().get('pid');
public String wtId = apexpages.currentpage().getparameters().get('wid');
public List<test__c> lstSWI{get;set;}
public wrapperSample objWS{get;set;}
public List<wrapperSample> lstWS{get;set;}
public sampleitem(){
    lstSWI = new List<test__c>();
    lstSWI = new List<test__c>();
    lstSWI = [select id,name from test__c order by name];
    lstWS = new List<wrapperSample>();
    for(test__c objSWI : lstSWI){
        objWS = new wrapperSample();
        objWS.swi = objSWI;
        lstWS.add(objWS);
    }
}

public class wrapperSample{
    public test__c swi{get;set;}
    public boolean ischecked{get;set;}
}
}

And the VF page…

<apex:page controller="sampleitem">
  <apex:form >
      <apex:pageblock >
          <apex:pageblocksection >
              <apex:pageblocktable value="{!lstWS}" var="S">
                  <apex:column headerValue="Select">
                      <apex:inputcheckbox value="{!S.ischecked}"/>
                  </apex:column>
                  <apex:column headerValue="Name">
                      <apex:outputtext value="{!S.swi.Name}"></apex:outputtext>
                  </apex:column>
              </apex:pageblocktable>
          </apex:pageblocksection>
          <apex:commandButton value="Select" Action="{!doSelect}"/>
      </apex:pageblock>
  </apex:form>
</apex:page>

I get this…

enter image description here

Method 2

I think it’s the fact that your binding this APEX Class to the <apex:dataTable>.

I don’t think you can bind APEX Classes to dataTable this way, not positive, but I think your limited to sObject fields, not members of classes in APEX.


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x