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
Dave The RaveDave The Rave 

DML code error

I created a new (boolean) field "FakeFieldTrigger__c" on the contact object, defaut value = FALSE, I would like to change the value to TRUE, but get an error.

List<Contact> recList = [SELECT Id, FakeFieldTrigger__c FROM Contact WHERE FakeFieldTrigger__c = FALSE;  ];
for (Contact rec : recList) {
rec.FakeFieldTrigger__c = TRUE;
}
update recList;


Error:

Line: 1, Column: 5
Unexpected token '<'.

Can you help me update the value of this boolean field, I can then trigger my process in the process builder.

Thanks,

Dave
Raj VakatiRaj Vakati
Use this code .. Your SOQL statement was having some syntax error .. 
 
List<Contact> recList = [SELECT Id, FakeFieldTrigger__c FROM Contact WHERE FakeFieldTrigger__c = FALSE];
for (Contact rec : recList) {
rec.FakeFieldTrigger__c = TRUE;
}
update recList;

 
Travis Malle 9Travis Malle 9
Hello Dave,
This should work... Just an extra semicolon. Ona side note, this looks like something that would a great use case for the process builder. Any opportunity to do something decaritily as apposed to code would be time well spent.
 
list<contact> recList = [select Id, FakeFieldTrigger__c from contact where FakeFieldTrigger__c = false];
    for (contact rec : recList) {
        rec.FakeFieldTrigger__c = true;
    }
    update recList;

Please let me know if you have any questions
 
Dave The RaveDave The Rave
Now I got this error: (using code from Travis Malle 9)

Line: 22, Column: 1
System.LimitException: Apex CPU time limit exceeded
Dave The RaveDave The Rave
Maybe I need to limit the number of records.
Raj VakatiRaj Vakati
Use limit and run multiple times this code from dev console 
Travis Malle 9Travis Malle 9
Can you post all of your logic.. trigger included.
Dave The RaveDave The Rave
I am using a Sandbox environment. I have changed my fields around to reduce the number of records which will be selected.

I think my code below will work on the live server.
 
List<Contact> recList = [SELECT Id, ActiveRegistrationsCount__c, FakeFieldTrigger__c FROM Contact WHERE ActiveRegistrationsCount__c >0  LIMIT 10];
for (Contact rec : recList) {
rec.FakeFieldTrigger__c = 7;
}
update recList;

 
Dave The RaveDave The Rave
In the Sandbox, Partial Copy it seems that not all record data is available. So now I know it is not a complete mirror image of the production server. Thanks for everyone's help on this question.