You need to sign in to do that
Don't have an account?
SFDC Dummy
Getting Error in VF page:urgent
Hi
i have created a VF page on which i will be search record and after thar i want to delete the record on the slected checkbox
error
[Error] Error: Invalid field selected for SObject BankBook__c
i have created a VF page on which i will be search record and after thar i want to delete the record on the slected checkbox
error
[Error] Error: Invalid field selected for SObject BankBook__c
<apex:page controller="AccountMultipleSearchWithPagenationCLS1" action="{!searchAcc}" sidebar="false" showHeader="true"> <apex:define name="body"> <div style="width:900px;margin: 0px auto 10px auto;background-color:Gray;border: 1px solid black;"> <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100" style="background-color:Gray;"/> <script> function checkAll(cb) { var inputElem = document.getElementsByTagName("input"); for(var i=0; i<inputElem.length; i++) { if(inputElem[i].id.indexOf("checkedone")!=-1) inputElem[i].checked = cb.checked; } } </script> <apex:form > <apex:pageBlock id="thePb" title="Dynamic BankBook Search:"> <apex:pageblockSection id="thepbs"> <apex:inputField value="{!acc.From_Date__c}" /> <apex:inputField value="{!acc.To_Date__c}"/> <apex:inputField value="{!acc.Group_FUP__c}" required="false" id="accName"/> <apex:inputfield value="{!acc.Party_CodeFUP__c}"/> </apex:pageblockSection> <apex:pageblockButtons location="bottom"> <apex:commandButton value="Search" action="{!searchAcc}" /> <apex:commandButton value="Delete" action="{!searchAcc}" /> </apex:pageblockButtons> </apex:pageBlock> <apex:pageBlock title="BankBook Details" id="noRec" rendered="{! IF( accountList != null && accountList.size ==0 , true, false)}" > <apex:outputPanel > <h1>No Records Found </h1> </apex:outputPanel> </apex:pageBlock> <apex:pageBlock title="BankBook Details" id="details" rendered="{! IF( accountList != null && accountList.size >0, true, false)}" > <apex:dataTable value="{!accountList}" var="a" columnswidth="50px,50px" cellpadding="4" border="1"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox > <apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)"/> </apex:inputCheckbox> </apex:facet> <apex:inputCheckbox value="{!a.selected}" id="checkedone"> <apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/> </apex:inputCheckbox> </apex:column> <apex:column headervalue="Date" value="{!a.Txn_Date__c}" /> <apex:column headervalue="Related Bank Account" value="{!a.Related_Bank_Acc__c}" /> <apex:column headervalue="Payment Type" value="{!a.Credit_Debit__c}" /> <apex:column headervalue="Master Code" value="{!a.Entries_Code__c}" /> <apex:column headervalue="Master Name" value="{!a.Debtor_Name_formula__c}" /> <apex:column headervalue="Amount" value="{!a.Amount__c}" /> <apex:column headervalue="Debit" value="{!a.Credit__c}" /> <apex:column headervalue="Credit" value="{!a.Debit__c}" /> <apex:column headervalue="Narration" value="{!a.Narration__c }" /> </apex:dataTable> <apex:pageblockButtons > <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/> <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/> <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/> <apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/> </apex:pageblockButtons> </apex:pageBlock> <apex:messages /> </apex:form> </div> </apex:define> <center><br/> <b><i style="font-size:10px;color:red;">Developed By GlobalNest IT Solution Pvt.Ltd. <a href="http://www.globalnest.com" target="_blank">[http://www.Globalnest.com]</a> (2015)</i></b> </center><br/> </apex:page> --------------------------------------------------------------------------------------------------- public with sharing class AccountMultipleSearchWithPagenationCLS1 { public BankBook__c acc{get;set;} public List<accountwrapper> accountList1 {get;set;} public List<BankBook__c> accountList {get;set;} List<string> conditions = new List<string>(); private integer totalRecs = 0; private integer OffsetSize = 0; private integer LimitSize= 10; public List<BankBook__c> selectedAccounts = new List<BankBook__c>(); public List<accountwrapper> getAccounts() { return accountList1; } public AccountMultipleSearchWithPagenationCLS1() { accountList1 = new List<accountwrapper>(); for(BankBook__c a: [select Id, Txn_Date__c, Related_Bank_Acc__c, Credit_Debit__c,Entries_Code__c,Amount__c,Credit__c,Debit__c, Debtor_Name_formula__c,Narration__c from BankBook__c]) accountList1.add(new accountwrapper(a)); //return accountList; system.debug('==>AccountMultipleSearchWithPagenationCLS is calling==>'); acc = new BankBook__c(); //accountList = new List<Account>(); } public PageReference getSelected() { selectedAccounts.clear(); for(accountwrapper accwrapper: accountList1) if(accwrapper.selected == true) selectedAccounts.add(accwrapper.acc); return null; } public List<BankBook__c> GetSelectedAccounts() { if(selectedAccounts.size()>0) return selectedAccounts; else return null; } public PageReference deleteAll() { try{ List<BankBook__c> selAccounts=GetSelectedAccounts(); if(selAccounts.size()>0){ for(BankBook__c ac:selAccounts){ delete ac; System.debug('###########Data Deleted Successfully###########'); } } ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'Deleted successfully')); PageReference pageref=new PageReference('/apex/BulkDelete'); return pageref; } Catch(Exception e){ ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'Data Base Error')); return null; } } public void searchAcc(){ totalRecs = 0; OffsetSize = 0; if(accountList !=null && accountList.size()>0){ accountList=null; } searchAccounts (); conditions.clear(); } public Void searchAccounts(){ System.debug('Total Records is ==>'+totalRecs); System.debug('OffsetSize is ==>'+OffsetSize); if(accountList != null && !accountList.isEmpty()){ accountList.clear(); } String strQuery ='SELECT Id,Txn_Date__c,From_Date__c,To_Date__c,Related_Bank_Acc__c,CreatedDate,Credit_Debit__c,Entries_Code__c,Debtor_Name_formula__c ,Debit__c,Credit__c,Amount__c,Narration__c From BankBook__c'; if(acc.From_Date__c!=null){ String fromDate = acc.From_Date__c+''; fromDate = fromDate.split(' ',0)[0]+'T00:00:00.000Z'; conditions.add('CreatedDate >='+fromDate); } if(acc.To_Date__c!=null){ String toDate = acc.To_Date__c+''; toDate = toDate.split(' ',0)[0]+'T23:59:59.000Z'; conditions.add('createdDate <='+toDate); } if(acc.Party_CodeFUP__c!=null && acc.Party_CodeFUP__c!=''){ conditions.add('Party_CodeFUP__c Like \'%' +acc.Party_CodeFUP__c+'%\' '); } if(acc.Group_FUP__c!=null && acc.Group_FUP__c!=''){ conditions.add('Group_FUP__c Like\'%' +acc.Group_FUP__c+'%\' '); } if (conditions.size() > 0) { strQuery += ' WHERE ' + conditions[0]; for (Integer i = 1; i < conditions.size(); i++) strQuery += ' AND ' + conditions[i]; } if(totalRecs !=null && totalRecs ==0){ List<BankBook__c> accTemp = Database.query(strQuery); totalRecs = (accTemp !=null &&accTemp.size()>0)?accTemp.size():0; } system.debug('strQuery ==>'+strQuery ); // add sort and limits at the end strQuery += ' ORDER BY Name ASC, CreatedDate DESC LIMIT :LimitSize OFFSET :OffsetSize'; accountList =Database.query(strQuery); //conditions.clear(); //return accountList.size(); } public void FirstPage() { OffsetSize = 0; searchAccounts(); } public void previous() { OffsetSize = (OffsetSize-LimitSize); searchAccounts(); } public void next() { OffsetSize = OffsetSize + LimitSize; searchAccounts(); } public void LastPage() { OffsetSize = totalrecs - math.mod(totalRecs,LimitSize); searchAccounts(); } public boolean getprev() { if(OffsetSize == 0){ return true; } else { return false; } } public boolean getnxt() { if((OffsetSize + LimitSize) > totalRecs){ return true; } else { return false; } } public class accountwrapper { public BankBook__c acc{get; set;} public Boolean selected {get; set;} public accountwrapper(BankBook__c a) { acc = a; selected = false; } } }
The error you are getting is because the apex:dataTable has a value="accountList" at line 50 which in the controller is a list of the sObject BankBook__c. so you should be using the other list "accountList1" which is a list of the AccountWrapper class that has the field "selected".
You will also need to update the columns to reference the correct BankBook__c fields, so for example instead of a.Txn_Date__c it would be a.acc.Txn_Date__c. Here's how the new table should look like:
This would probably fix the error you are getting at the moment but the list will not be showing the search records that you want, you will need to also modify your controller and load the list accountList1 with the query results. starting at line 279:
Now you should have the query results in the accountWrapper list and have your VF page working as you need.
Hope this helps.
Cheers,
Peter