+ Start a Discussion
RimaRima 

How to represent checkbox data type in Apex code

Hi All,

 

I am getting the following error from the apex code.

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_TYPE_ON_FIELD_IN_RECORD, Currently employed: value not of required type: :

 

private boolean Experience;

 

controller.setExperience(true);

 

Construction_experience__c = ConExperience;

 

Construction_experience__c  is a checkbox datatype custom field.I want to assign a value to it in Apex code.I am setting the value of the Experience checkbox to true using setExperience method. Could anyone please let me know what is the wrong with the declared boolean data type? How to assign value to checkbox data type in Apex code? Your help is greatly appreciated.

rmehrmeh

Hi Rima,

 

Can you just put a System.debug and check what value is getting set.

I think the value is not properly getting assigned to it.

RimaRima

Hi,


Thank you for your response. I have put a system.debug statement as follows:

controller.setExperience(true);
system.debug('Experience that was added' +  Construction_experience__c );     

I got Construction_experience__c field value as 'true'.  

16:32:13.555|USER_DEBUG|[55,5]|DEBUG|Experience that was addedtrue

 

My intention is to pass the value of the checkbox to Construction_experience__c  variable. I am considering value 'true' if the checkbox is checked and 'false' if the checkbox is unchecked.

I am not sure why I am getting following error message when I am passing proper value.Any help on this is greatly appreceated.

 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_TYPE_ON_FIELD_IN_RECORD, Currently employed: value not of required type: : [Construction_experience__c]

Pradeep_NavatarPradeep_Navatar

Declare the checkbox variable in your code as shown below :

 

Public boolean Construction_experience__c{get;set;}

 

Hope this helps.

SaintMichaelSaintMichael

Rima, did you ever resolve this?

 

I am having the same problem with a JQuery checkbox.