Find your content:

Search form

You are here

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

 
Share

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]

Attribution to: rakesh

Possible Suggestion/Solution #1

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.


Attribution to: jordan.baucke

Possible Suggestion/Solution #2

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


Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4560

My Block Status

My Block Content