2

I am trying to do a simple task via Anonymous window.

Something like below:

A__c aInstance = new A__c();
aInstance.B__c = 'Some value';
insert aInstance;

When I Execute this code, I get error pop up with message something like below:

Line: 2, Column: 10

Variable does not exist: B__c

Additionally, this error is coming for any field of object A__c, regardless of field type.

Is anybody aware about such issue?

2
  • 1
    Are A__c and B__c custom objects/fields, or standard? Are you logged in with a profile that can see the object (Object Level Security) and field (Field Level Security) for the object/field in question?
    – sfdcfox
    Commented Jul 9 at 20:01
  • 1
    A__c is cusom object and B__c is custom field. These are newly created. I checked in my profile that I do not have read/write access to the fields. Given access to myself. Now working fine. Thanks Commented Jul 9 at 20:07

1 Answer 1

1

Execute Anonymous is slightly different than all other kinds of Apex. Namely, it does strictly enforce object and field level security at compile time. Your user account must have access to any fields and objects that you want to use in your code, either by profile or permission set. These permissions must exist before the transaction starts. In other words, you can't write Apex code that will insert a Permission Set Assignment that gives you access to those fields or objects.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .