function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
duke1duke1 

Process checkbox in Trigger

How can I process a checkbox field in apex code (not with DeveloperForce)?  In my trigger I want to see if the field is checked and after processing it, uncheck the field.  I cannot find examples of this.  I want my user to check a checkbox of accounts to be processed, this will invoke the bulk trigger.  Can anyone help?  I can't find any examples after much searching.

Best Answer chosen by Admin (Salesforce Developers) 
dhoechstdhoechst

I think your trigger needs to be BeforeUpdate. This will allow you to modify fields before the record is committed to the database. By having your trigger AfterUpdate, the record has already been committed and thus is read only.

All Answers

hisrinuhisrinu

You just need to assign TRUE or FALSE value

 

for(account a : trigger.new)

a.checkbox = true;

duke1duke1

Hi Srini,

 

I keep getting the following error when I update the checkbox to false at the end of my trigger:

 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SumCansTransTrigger: execution of AfterUpdate caused by: System.FinalException: Record is read-only

 

Do you know how to work around this problem?

 

Thanks,

Duke1

dhoechstdhoechst

I think your trigger needs to be BeforeUpdate. This will allow you to modify fields before the record is committed to the database. By having your trigger AfterUpdate, the record has already been committed and thus is read only.

This was selected as the best answer
duke1duke1

OK, thanks.