You need to sign in to do that
Don't have an account?

If condition on a checkbox
Hello everybody,
I would like to know how do you check the value of a checkbox (isDone__c), whether it is true or false.
I have tried this: if(isDone__c) and I am getting the following error: Condition expression must be of type Boolean.
Thanks for any help,
Vijay,
Hi Vijay,
Yes you can ,Try like below .
Boolean isChecked=work.isDone__c;
All Answers
You are correct but only one thing you are missing ,you need to check like below
Assume the field in account object then Account acc;
If(acc.isDone__c)
Lt me know any issue .
Is this a property in apex or a field in an object?
Thanks
Nitin
Hi!
The filed in found in Work object, therefore (work.isDone__c).
Even then, I have the same error.
Regards,
Vijay
try below code
If(work.isDone__c == True){
}
let me know if it helps !
Confirm one time whether the field is checkbox and do a system.debug for work.isDone__c atlast you can try like this if(work.isDone__c == true)
Regards,
Praveen Murugesan
I have tried the code
If(work.isDone__c == True){
...
}
But I get the error: Comparison arguments must be compatible types: Schema.SObjectField, Boolean
What is the type of isDone__c ?
isDone__c is a checkbox.
Hi Vijay,
Yes you can ,Try like below .
Boolean isChecked=work.isDone__c;
You might have forgotten to mention the trigger context.
work workcheck = Trigger.new[0]; // if you want to check on the first record
then if(workcheck.isDone__c) will work.
In case you forget to do this, you have to explicitly change the field type to boolean
eg : Boolean isChecked=work.isDone__c;
VFpage:
<apex:page controller="SelCheckBox_cntrl">
<apex:form >
<apex:pageBlock title="Select Student Name">
<apex:SelectCheckboxes value="{!coolbool}">
<apex:SelectOptions value="{!StudentNames}"/>
<apex:actionSupport event="onclick" reRender="messagebox"/>
</apex:SelectCheckboxes>
</apex:pageBlock>
<apex:pageBlock title="Related Selected Reports">
<apex:pageBlockTable value="{!srep}" var="SR">
<apex:column value="{!SR.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton value="Get Selected Reports" action="{!selctedReports}"/>
</apex:form>
</apex:page>
APEX code:
public class SelCheckBox_cntrl {
public String StudentDetails{set;get;}
public List<Student_Reports__c> srep{set;get;}
public Boolean coolbool{set;get;}
public SelCheckBox_cntrl(){
srep = new List<Student_Reports__c>();
coolbool = false;
}
public List<SelectOption> getStudentNames(){
List<SelectOption> Sel = new List<SelectOption>();
for(Student_Details__c SD : [Select id,Name from Student_Details__c]){
Sel.add(new SelectOption(SD.id,SD.Name));
}
return Sel;
}
public void selctedReports(){
if(coolbool==true){
srep = [Select id,Name,Student_Name__c,Test1__c,Test2__c,Test3__c,Certification__c,Result__c from Student_Reports__c where Student_Name__c=:StudentDetails];
}
else{
system.debug('Select any Name');
}
}
}