You need to sign in to do that
Don't have an account?
Yuta Furusawa
Create CheckBox
Hello, Please advice me to how to create checkbox.
I made a Employee Search and Delete page on visual force for practice.
And now I want to add checkbox on my search results. This checkbox should be work for delete employee.
This is my VF page
This is my Apex Controller(Sorry, its very long)
I made a Employee Search and Delete page on visual force for practice.
And now I want to add checkbox on my search results. This checkbox should be work for delete employee.
This is my VF page
<apex:page controller="EmployeeDelete3Controller"> <apex:form > <apex:pageBlock title="EmployeeDelete"> <apex:pageBlockSection columns="1"> <apex:inputField required="false" value="{!info.Employee_Name__c}"/> <apex:inputField required="false" value="{!info.Employee_DOB__c}"/> <apex:inputField required="false" value="{!info.Employee_Mailaddress__c}"/> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!search}" value="Search"/> </apex:pageBlockButtons> <apex:variable id="rowIndex" var="rowIndex" value="1" /> <apex:pageBlockTable value="{!results}" var="in"> <apex:column headerValue="No"> <apex:outputText value="{!VALUE(rowIndex)}"/> <apex:variable var="rowIndex" value="{!VALUE(rowIndex) + 1}"/> </apex:column> <apex:column value="{!in.Employee_Name__c}"/> <apex:column value="{!in.Employee_DOB__c}"/> <apex:column value="{!in.Employee_Mailaddress__c}"/> <apex:column headerValue="Delete"> <apex:commandLink action="{!delEmp}" value="Delete"> <apex:param value="{!in.Id}" assignTo="{!deleteEmployee}" name="deleteEmployee"/> </apex:commandLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> <apex:messages /> </apex:page>
This is my Apex Controller(Sorry, its very long)
public class EmployeeDelete3Controller { public Employee_Management__c info { get;set; } public List<Employee_Management__c> results { get;set; } public string deleteEmployee { get;set; } Public List<Employee_Management__c> deleteEmpResult{ get;set; } public EmployeeDelete3Controller(){ results = new List<Employee_Management__c>(); info = new Employee_Management__c(); deleteEmpResult= new List<Employee_Management__c>(); } public PageReference search(){ String strSoqlQuery1; String strSoqlQuery2; String strSoqlQuery3; String strSoqlQuery4; String strSoqlQuery5; String strSoqlQuery6; String strSoqlQuery7; string strEmployeeMailaddressc; string strEmployeeNamec; String deleteEmployee; IF(!String.IsBlank(info.Employee_Name__c) && !String.IsBlank(info.Employee_Mailaddress__c) && info.Employee_DOB__c != null) { strEmployeeNamec = info.Employee_Name__c; strEmployeeMailaddressc = info.Employee_Mailaddress__c; strSoqlQuery1 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c Where Employee_Name__c = \'' + strEmployeeNamec + '\' Or Employee_Mailaddress__c = \'' + strEmployeeMailaddressc + '\' Or Employee_DOB__c =' + String.valueOf(info.Employee_DOB__c); results = database.query(strSoqlQuery1); } else if(!String.IsBlank(info.Employee_Name__c) && !String.IsBlank(info.Employee_Mailaddress__c)) { strEmployeeNamec = info.Employee_Name__c; strEmployeeMailaddressc = info.Employee_Mailaddress__c; strSoqlQuery2 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c where Employee_Name__c = \'' + strEmployeeNamec + '\' Or Employee_Mailaddress__c = \'' + strEmployeeMailaddressc + '\''; results = database.query(strSoqlQuery2); } else if(!String.IsBlank(info.Employee_Name__c) && info.Employee_DOB__c != null) { strEmployeeNamec = info.Employee_Name__c; strSoqlQuery3 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c WHERE Employee_Name__c = \'' + strEmployeeNamec + '\' Or Employee_DOB__c =' + String.valueOf(info.Employee_DOB__c); results = database.query(strSoqlQuery3); } else if(!String.IsBlank(info.Employee_Name__c)) { strEmployeeNamec = info.Employee_Name__c; strSoqlQuery4 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c where Employee_Name__c = \'' + strEmployeeNamec + '\''; results = database.query(strSoqlQuery4); } else if(!String.IsBlank(info.Employee_Mailaddress__c) && info.Employee_DOB__c != null) { strEmployeeMailaddressc = info.Employee_Mailaddress__c; strSoqlQuery5 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c where Employee_Mailaddress__c = \'' + strEmployeeMailaddressc + '\' Or Employee_DOB__c =' + String.valueOf(info.Employee_DOB__c); results = database.query(strSoqlQuery5); } else if(!String.IsBlank(info.Employee_Mailaddress__c)) { strEmployeeMailaddressc = info.Employee_Mailaddress__c;//info.Employee_Mailaddress__cをstrEmployeeMailaddresscに割り当て strSoqlQuery6 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c where Employee_Mailaddress__c = \'' + strEmployeeMailaddressc + '\''; results = database.query(strSoqlQuery6); } else if (info.Employee_DOB__c != null) { strSoqlQuery7 = 'SELECT Employee_Name__c, Employee_Mailaddress__c, Employee_DOB__c FROM Employee_Management__c WHERE Employee_DOB__c = '+ String.valueOf(info.Employee_DOB__c); results = database.query(strSoqlQuery7); } else { ApexPages.Message message = new ApexPages.Message( ApexPages.severity.ERROR, 'ERROR'); ApexPages.addMessage(message); } return null; } public PageReference delEmp() { string deleteEmployee = 'SELECT Id, Employee_Name__c, Employee_DOB__c, Employee_Mailaddress__c FROM Employee_Management__c where id=' + '\'' + deleteEmployee + '\''; deleteEmpResult = database.query(deleteEmployee); delete deleteEmpResult; return Page.EmpDel2; } }I`m so sorry that my English skill is very low.
If I get the question correct you are looking for a way to add a checkbox to every row in visualforce datatable records where you can select multiple records and you need to delete these records that have been selected, if that is correct then I would suggest you to have a look at the below implementations as they are of same use case.
>> https://salesforce.stackexchange.com/questions/117058/how-to-delete-the-multiple-record-with-checkbox
>> https://developer.salesforce.com/forums/?id=906F0000000MJq9IAG
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
I tried to modify the code by referring to the article you sent me, but when I created the Wrapper class at bottom of the controller and I'm getting errors which are Do I need to convert the List to resolve this error?