I cannot update update this Boolean value in Apex. What is going wrong? The if statement, and the fact that the front end representation is a checkbox, proves that it is indeed a boolean value. I am new to Apex so I feel its a basic misunderstanding of how it works. Can anyone help me out?
Here is the code that I'm executing in an Anonymous Window.
Account acc = new Account(Name='Test Name');
if (acc.Do_Not_Contact__pc == false) {
System.debug('DNC is false');
} else {
System.debug('DNC is true');
}
insert acc;
acc.Do_Not_Contact__pc = true;
update acc;
It fails on the second to last line, displaying the following message:
System.DmlException: Update failed. First exception on row 0 with id 001W000000fFiVbIAK; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Do_Not_Contact__pc: [Do_Not_Contact__pc]
What's particularly frustrating is that when I change the second to last line to
acc.Do_Not_Contact__pc = 'true';
I get an error stating that I cannot assign a String to a Boolean value
Edit 1: Here is an image showing the Account field configuration
Edit 2:
Full field configuration
Do_Not_Contact__pc
is the right field name? Have you set up Person Accounts in your org? Can you include a screenshot of your field configuration? – Adrian Larson♦ Feb 22 '18 at 22:39Do_Not_Contact__pc
is the right field name. When I changeDo_Not_Contact__pc
toDo_Not_Contact__c
on line 2 I get an errorVariable does not exist: Do_Not_Contact__c
– Briscoooe Feb 22 '18 at 22:43