You need to sign in to do that
Don't have an account?
Vincent van Drunen Littel
Add function not working in code *urgent*
Hi, ive been working around this script and its almost as perfect as it can get for me, just the "most important" function is not working
the button "add target"
Error: Compile Error: Variable does not exist: selectedlstAccounts at line 27 column 40
Can someone give me a hand fixing this one??
Controler
the button "add target"
Error: Compile Error: Variable does not exist: selectedlstAccounts at line 27 column 40
Can someone give me a hand fixing this one??
Controler
public with sharing class CustomPaginationController { public Contact acc {get;set;} public ApexPages.StandardSetController con{get; set;} public CustomPaginationController () { acc = new Contact(); lstAccount = new List<Contact>(); } public List<Contact> lstAccount { get { if(con != null) return (List<Contact>)con.getRecords(); else return null ; } set; } //added by me to test public PageReference addTarget() { //system.debug('sssssssss'); List<Contact> lstAccountsIds = selectedlstAccounts.split(','); List<Target__c> lstAccount = new List<Target__c>(); //system.debug('rrrrrrr'); for (string s : lstAccountsIds ) { //system.debug('lstAccountsIds: ' + lstAccountsIds); system.debug('s: ' + s); system.debug('Name: ' + accountMap.get(s).Name); Target__c newtarget = new Target__c (Target__c = lstAccount, Name = lstAccountsMap.get(s).Name); Target.add(newtarget); } //system.debug('yyyyyyy'); if (Target.size() > 0) { //system.debug('ppppppp'); insert lstAccount; } string strPageRef = '"javascript:window.close();"'; return new PageReference(strPageRef); } public PageReference Search() { String query= ''; String strFilter = ''; if(acc.Name != null && (acc.Name ).trim() !='') { strFilter = strFilter + ' where Name Like \''+acc.Name+'%\'' ; } if(acc.Account.Name != null && (acc.Account.Name).trim() !='' ) { strFilter = strFilter + ' where Name Like \''+acc.Account.Name+'%\'' ; } if(strFilter != '') { query = 'Select name ,id, Account.Name, Cargo__c from Contact '+strFilter+ ' limit 1000'; System.debug('Query ---->'+ query ); con = new ApexPages.StandardSetController(Database.getQueryLocator(query)); con.setPageSize(10); } else { } return null; } public Boolean hasNext { get { return con.getHasNext(); } set; } public Boolean hasPrevious { get { return con.getHasPrevious(); } set; } public Integer pageNumber { get { return con.getPageNumber(); } set; } public void previous() { con.previous(); } public void next() { con.next(); } }VFpage
<apex:page controller="CustomPaginationController" sidebar="false"> //I added this <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <script type="text/javascript"> $ = jQuery.noConflict(); function Select1stAccounts(chk, contactId, Account.Name) { alert( '1' ); var lstAccounts = $('input[id$="lstAccounts"]'); var selectedlstAccounts = lstAccounts.val(); if (chk.checked == true) { alert( '2A' ); if (selectedlstAccounts == '') { alert( '2A1' ); selectedlstAccounts = lstAccounts; } else { alert( '2A2' ); selectedlstAccounts = selectedlstAccounts + ',' + lstAccounts; } } else { alert( '2B' ); var accountIndex = selectedlstAccounts.indexOf(contactId); var accountToRemove = ''; if (selectedlstAccounts.length == lstAccounts.length) { accountToRemove = lstAccounts; } else { if (accountIndex == 0){ accountToRemove = lstAccounts+ ','; } else{ accountToRemove = ',' + lstAccounts; } } selectedlstAccounts = selectedlstAccounts.replace(accountToRemove, ''); } alert( 'B' ); lstAccounts.val(selectedlstAccounts); alert (lstAccounts.val()); } </script> //Orignal Code <apex:form > <apex:inputHidden value="{!selectedlstAccounts}" id="lstAccountsIds"/> <apex:pageBlock > <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Search}" value="Search" /> </apex:pageBlockButtons> <apex:pageblockSection > <apex:inputText value="{!acc.Name}" label="Name"/> </apex:pageblockSection> </apex:pageBlock> <apex:pageBlock id="resultId" rendered="{!if(lstAccount != null && lstAccount.size > 0, true,false )}"> <apex:pageBlockButtons > <div style="text-align:right"> Total Records Found: {!Con.resultSize} <apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(Con.HasPrevious)}"/> <apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!Con.HasPrevious}"/> <apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!Con.HasPrevious}"/> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasPrevious)}">Previous Page</apex:outputPanel> <apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(Con.HasNext)}">Next Page</apex:outputPanel> <apex:commandLink title="Next Page" value="Next Page" rendered="{!Con.HasNext}" action="{!Next}"/> <apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!Con.HasNext}"/> <apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(Con.HasNext)}"/> <img src="/s.gif" title="Last Page" alt="Last Page" class="last"/> </div> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!lstAccount}" var="acc" > <apex:column headerValue="Select" width="100px;"> <apex:inputCheckbox onclick="javascript:SelectAccounts(this, '{!acc.Id}');"/> </apex:column> <apex:column value="{!acc.Name}"/> <apex:column value="{!acc.Account.Name}"/> <apex:column value="{!acc.Cargo__c}"/> </apex:PageblockTable> <apex:commandButton value="Add Target" action="{!addTargets}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Thanks
Amit Chaudhary
All Answers
Sorry but I'm new to apex, and not sure what you mean, would you be able to show me how its done?
----------------------------------------------------------------------------------
public String selectedlstAccounts { set; get; }
---------------------------------------------------------------------------------------------
in your Controller.
Thanks!
Thank you
public String selectedlstAccounts { set; get; }
as Property.
Thanks
Amit Chaudhary