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
American DataAmerican Data 

Exception When Querying Lead field HasOptedOutOfEmail

Hello,

When attempting to perform the following query:

select ID, HasOptedOutOfEmail, Email from Lead where HasOptedOutOfEmail = false

I'm receiving the following error:

INVALID_FIELD: Bad field name 'HasOptedOutOfEmail' in select list of query call. Either this field does not exist, or access to this field is restricted by field level security settings.

There is another query within my program that runs without problem, and uses the Lead HasOptedOutOfEmail field.

Select CreatedDate, FirstName, LastName, Email, ID from Lead Where CreatedDate >= 2005-11-15T00:00:00-07:00 And CreatedDate < 2005-11-16T00:00:00-07:00 And Status = 'Open' And HasOptedOutOfEmail = false

I've reviewed the field level security settings and all the levels are set to visible. None are marked as read-only.

Any assistance in resolving why I'm receiving this exception in the first query but not the second is greatly appreciated.

Thank you,

Josh