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
sales4cesales4ce 

Trigger Not compiling

Hello,

 

I have written a simple trigger, but it does not compile for some reason.

I have a checkbox on my Campaign object called "High_Campaign__c" and a custom field of type text "Testing__c"

whenever the "High_Campaign__c" is checked i want to populate some text into custom field.

 

how do i check if a checkbox is checked or not? (like checkbox.checked=true).

Am i doing anything wrong?

 

The error is: execution of AfterUpdate caused by: System.Exception: Record is read-only: Trigger.TasksfornewMembers: line 6, column 12

 

Here is the code:

 

trigger TasksfornewMembers on Campaign (after Insert,after update) {

    for(Campaign c: Trigger.New)
    {
        if(c.High_Campaign__c=True)
           c.Testing__c='Hi I am Checked';
    }

}
Best Answer chosen by Admin (Salesforce Developers) 
incuGuSincuGuS

If you are gonna edit the record you just created, i suggest doing it on Before Insert, within the trigger modify it so that when it resolves changes are also impacted on the record being created. This way you create a X record, it triggers the on before, you modify it and its created with the modifications.

 

All Answers

incuGuSincuGuS

 

trigger TasksfornewMembers on Campaign (after Insert,after update) {

    for(Campaign c: Trigger.New)
    {
        if(c.High_Campaign__c==True)
           c.Testing__c='Hi I am Checked';
    }

}

 

Notice the "==" instead of "="

 

 

if(c.High_Campaign__c==True)

 

You were assigning a value instead of comparing :) .

Double = means compare if its value is equal to,  one = is assign value to variable.

 

Hope this helps you,

Gaston.

 

 

sales4cesales4ce

Hi Gaston,

 

Infact it was '==' and still it raises the same error. i am little confused.

I see the error/exception as Record is read only.But to my surprise i have all permissions enabled on my profile. Infact i am using System admin profile.

When  deactivate the trigger it is working fine. i can edit it...

 

Still am i missing anything?

 

Thanks,

Sales4ce

incuGuSincuGuS

If you are gonna edit the record you just created, i suggest doing it on Before Insert, within the trigger modify it so that when it resolves changes are also impacted on the record being created. This way you create a X record, it triggers the on before, you modify it and its created with the modifications.

 

This was selected as the best answer