You need to sign in to do that
Don't have an account?
Mahesh Dhara 9
Is Anything Wrong with My code when I am selecting check box that records are not added to the selectdCandidates List
Controller:
public class Position_Candidate_Records_AC {
public Position__c position {set;get;}
public List<Candidate__c> candidates {set;get;}
public List<CandidateWraper> candidateList {set;get;}
public Integer counter {set;get;}
public Position_Candidate_Records_AC(ApexPages.StandardController controller){
position=[Select id,Name,Functional_Area__c,Max_Pay__c,Min_Pay__c from Position__c where Id=: ApexPages.currentPage().getParameters().get('id')];
candidates=[Select id,Name, Positin__c,City__c,Country__c,Email__c,Exp__c,Positin__r.Name from Candidate__c where Positin__r.Name=:position.Name];
counter=0;
candidateList=new List<CandidateWraper>();
for(Candidate__c c:candidates){
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
}
}
public PageReference addRow(){
Candidate__c c=new Candidate__c();
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
return null;
}
public PageReference removeRow(){
Integer param = Integer.valueOf(Apexpages.currentpage().getParameters().get('index'));
for(Integer i=0;i<candidateList.size();i++){
if(candidateList[i].counterWrap == param ){
candidateList.remove(i);
}
}
counter--;
return null;
}
public PageReference deleteSelected(){
List<Candidate__c> selectedCandidates=new list<Candidate__c>();
for(CandidateWraper cw:candidateList){
if(cw.isSelected==true){
System.debug('hi');
selectedCandidates.add(cw.candidate);
}
}
if(!selectedCandidates.isEmpty()){
delete selectedCandidates;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records deleted Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
public PageReference saveAll(){
List<Candidate__c> updateCandidateList=new List<Candidate__c>();
if(!candidateList.isEmpty()){
for(CandidateWraper cw:candidateList){
updateCandidateList.add(cw.candidate);
}
}
if(!updateCandidateList.isEmpty()){
upsert updateCandidateList;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records Saved Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
Public class CandidateWraper{
public Candidate__c candidate {set;get;}
public Integer counterWrap {set;get;}
public boolean isSelected {set;get;}
}
}
public class Position_Candidate_Records_AC {
public Position__c position {set;get;}
public List<Candidate__c> candidates {set;get;}
public List<CandidateWraper> candidateList {set;get;}
public Integer counter {set;get;}
public Position_Candidate_Records_AC(ApexPages.StandardController controller){
position=[Select id,Name,Functional_Area__c,Max_Pay__c,Min_Pay__c from Position__c where Id=: ApexPages.currentPage().getParameters().get('id')];
candidates=[Select id,Name, Positin__c,City__c,Country__c,Email__c,Exp__c,Positin__r.Name from Candidate__c where Positin__r.Name=:position.Name];
counter=0;
candidateList=new List<CandidateWraper>();
for(Candidate__c c:candidates){
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
}
}
public PageReference addRow(){
Candidate__c c=new Candidate__c();
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
return null;
}
public PageReference removeRow(){
Integer param = Integer.valueOf(Apexpages.currentpage().getParameters().get('index'));
for(Integer i=0;i<candidateList.size();i++){
if(candidateList[i].counterWrap == param ){
candidateList.remove(i);
}
}
counter--;
return null;
}
public PageReference deleteSelected(){
List<Candidate__c> selectedCandidates=new list<Candidate__c>();
for(CandidateWraper cw:candidateList){
if(cw.isSelected==true){
System.debug('hi');
selectedCandidates.add(cw.candidate);
}
}
if(!selectedCandidates.isEmpty()){
delete selectedCandidates;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records deleted Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
public PageReference saveAll(){
List<Candidate__c> updateCandidateList=new List<Candidate__c>();
if(!candidateList.isEmpty()){
for(CandidateWraper cw:candidateList){
updateCandidateList.add(cw.candidate);
}
}
if(!updateCandidateList.isEmpty()){
upsert updateCandidateList;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records Saved Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
Public class CandidateWraper{
public Candidate__c candidate {set;get;}
public Integer counterWrap {set;get;}
public boolean isSelected {set;get;}
}
}
Vf Page
<apex:page standardController="Position__c" extensions="Position_Candidate_Records_AC" tabStyle="Account" sidebar="false" >
<apex:sectionHeader title="Position" subtitle="{!Position__c.Name}"/>
<apex:messages />
<apex:form >
<apex:pageBlock title="Position Details">
<apex:pageBlockTable value="{!position}" var="p">
<apex:column headerValue="PositionName" value="{!p.Name}" />
<apex:column headerValue="Functional Area" value="{!p.Functional_Area__c}" />
<apex:column headerValue="Max Pay" value="{!p.Max_Pay__c}" />
<apex:column headerValue="Min Pay" value="{!p.Min_Pay__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Candidate Details" id="pb1">
<apex:pageBlockButtons location="Top">
<apex:commandButton value="Save" action="{!saveAll}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:pageBlockTable value="{!candidateList}" var="c" id="pb1" >
<apex:column headerValue="Action">
<apex:commandLink value="Remove" action="{!removeRow}" immediate="true" reRender="pb1">
<apex:param name="index" value="{!c.counterWrap}"/>
</apex:commandLink>
</apex:column>
<apex:column headerValue="Check">
<apex:inputCheckbox value="{!c.isSelected}" id="InputId"/>
</apex:column>
<apex:column headerValue="Position" >
<apex:inputField value="{!c.candidate.Positin__c}" />
</apex:column>
<apex:column headerValue="City">
<apex:inputField value="{!c.candidate.City__c}" />
</apex:column>
<apex:column headerValue="Country">
<apex:inputField value="{!c.candidate.Country__c}" />
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!c.candidate.Email__c}" />
</apex:column>
<apex:column headerValue="Exp">
<apex:inputField value="{!c.candidate.Exp__c}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="AddRow" action="{!addRow}" reRender="pb1" immediate="true" />
<apex:commandButton value="DeleteSelected" action="{!deleteSelected}" immediate="true"/>
</apex:pageBlock>
</apex:form>
</apex:page>
public class Position_Candidate_Records_AC {
public Position__c position {set;get;}
public List<Candidate__c> candidates {set;get;}
public List<CandidateWraper> candidateList {set;get;}
public Integer counter {set;get;}
public Position_Candidate_Records_AC(ApexPages.StandardController controller){
position=[Select id,Name,Functional_Area__c,Max_Pay__c,Min_Pay__c from Position__c where Id=: ApexPages.currentPage().getParameters().get('id')];
candidates=[Select id,Name, Positin__c,City__c,Country__c,Email__c,Exp__c,Positin__r.Name from Candidate__c where Positin__r.Name=:position.Name];
counter=0;
candidateList=new List<CandidateWraper>();
for(Candidate__c c:candidates){
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
}
}
public PageReference addRow(){
Candidate__c c=new Candidate__c();
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
return null;
}
public PageReference removeRow(){
Integer param = Integer.valueOf(Apexpages.currentpage().getParameters().get('index'));
for(Integer i=0;i<candidateList.size();i++){
if(candidateList[i].counterWrap == param ){
candidateList.remove(i);
}
}
counter--;
return null;
}
public PageReference deleteSelected(){
List<Candidate__c> selectedCandidates=new list<Candidate__c>();
for(CandidateWraper cw:candidateList){
if(cw.isSelected==true){
System.debug('hi');
selectedCandidates.add(cw.candidate);
}
}
if(!selectedCandidates.isEmpty()){
delete selectedCandidates;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records deleted Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
public PageReference saveAll(){
List<Candidate__c> updateCandidateList=new List<Candidate__c>();
if(!candidateList.isEmpty()){
for(CandidateWraper cw:candidateList){
updateCandidateList.add(cw.candidate);
}
}
if(!updateCandidateList.isEmpty()){
upsert updateCandidateList;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records Saved Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
Public class CandidateWraper{
public Candidate__c candidate {set;get;}
public Integer counterWrap {set;get;}
public boolean isSelected {set;get;}
}
}
public class Position_Candidate_Records_AC {
public Position__c position {set;get;}
public List<Candidate__c> candidates {set;get;}
public List<CandidateWraper> candidateList {set;get;}
public Integer counter {set;get;}
public Position_Candidate_Records_AC(ApexPages.StandardController controller){
position=[Select id,Name,Functional_Area__c,Max_Pay__c,Min_Pay__c from Position__c where Id=: ApexPages.currentPage().getParameters().get('id')];
candidates=[Select id,Name, Positin__c,City__c,Country__c,Email__c,Exp__c,Positin__r.Name from Candidate__c where Positin__r.Name=:position.Name];
counter=0;
candidateList=new List<CandidateWraper>();
for(Candidate__c c:candidates){
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
}
}
public PageReference addRow(){
Candidate__c c=new Candidate__c();
CandidateWraper cw=new CandidateWraper();
counter++;
cw.candidate=c;
cw.counterWrap=counter;
cw.isSelected=false;
candidateList.add(cw);
return null;
}
public PageReference removeRow(){
Integer param = Integer.valueOf(Apexpages.currentpage().getParameters().get('index'));
for(Integer i=0;i<candidateList.size();i++){
if(candidateList[i].counterWrap == param ){
candidateList.remove(i);
}
}
counter--;
return null;
}
public PageReference deleteSelected(){
List<Candidate__c> selectedCandidates=new list<Candidate__c>();
for(CandidateWraper cw:candidateList){
if(cw.isSelected==true){
System.debug('hi');
selectedCandidates.add(cw.candidate);
}
}
if(!selectedCandidates.isEmpty()){
delete selectedCandidates;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records deleted Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
public PageReference saveAll(){
List<Candidate__c> updateCandidateList=new List<Candidate__c>();
if(!candidateList.isEmpty()){
for(CandidateWraper cw:candidateList){
updateCandidateList.add(cw.candidate);
}
}
if(!updateCandidateList.isEmpty()){
upsert updateCandidateList;
}
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Records Saved Successfully.');
ApexPages.addMessage(myMsg);
return null;
}
Public class CandidateWraper{
public Candidate__c candidate {set;get;}
public Integer counterWrap {set;get;}
public boolean isSelected {set;get;}
}
}
Vf Page
<apex:page standardController="Position__c" extensions="Position_Candidate_Records_AC" tabStyle="Account" sidebar="false" >
<apex:sectionHeader title="Position" subtitle="{!Position__c.Name}"/>
<apex:messages />
<apex:form >
<apex:pageBlock title="Position Details">
<apex:pageBlockTable value="{!position}" var="p">
<apex:column headerValue="PositionName" value="{!p.Name}" />
<apex:column headerValue="Functional Area" value="{!p.Functional_Area__c}" />
<apex:column headerValue="Max Pay" value="{!p.Max_Pay__c}" />
<apex:column headerValue="Min Pay" value="{!p.Min_Pay__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Candidate Details" id="pb1">
<apex:pageBlockButtons location="Top">
<apex:commandButton value="Save" action="{!saveAll}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:pageBlockTable value="{!candidateList}" var="c" id="pb1" >
<apex:column headerValue="Action">
<apex:commandLink value="Remove" action="{!removeRow}" immediate="true" reRender="pb1">
<apex:param name="index" value="{!c.counterWrap}"/>
</apex:commandLink>
</apex:column>
<apex:column headerValue="Check">
<apex:inputCheckbox value="{!c.isSelected}" id="InputId"/>
</apex:column>
<apex:column headerValue="Position" >
<apex:inputField value="{!c.candidate.Positin__c}" />
</apex:column>
<apex:column headerValue="City">
<apex:inputField value="{!c.candidate.City__c}" />
</apex:column>
<apex:column headerValue="Country">
<apex:inputField value="{!c.candidate.Country__c}" />
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!c.candidate.Email__c}" />
</apex:column>
<apex:column headerValue="Exp">
<apex:inputField value="{!c.candidate.Exp__c}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="AddRow" action="{!addRow}" reRender="pb1" immediate="true" />
<apex:commandButton value="DeleteSelected" action="{!deleteSelected}" immediate="true"/>
</apex:pageBlock>
</apex:form>
</apex:page>
check box state is not changing it is alwaycs showing false wheather it is enable also