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
kyle.olson1.393882558611674E12kyle.olson1.393882558611674E12 

Case.AccountId returns NULL for non-administrators

I have an error that is caused by the Case.AccountId field equalling NULL when inside a Before Insert Case Trigger. When viewing the page layout before first saving the record, the account is visibly populated. When logged in as an administrator everything works properly, but when logged in as a custom profile the trigger cannot read the account id. I have checked field level security on the Case object and all profiles have the Visible box checked. Does anyone know any other common reasons why a field would show up as NULL for only certain profiles?

Thanks for any help you can provide.
bob_buzzardbob_buzzard
That seems very odd - triggers run in the system context so the CRUD and FLS for the current user would be disregarded.  Presumably there isn't another trigger clearing this field for particular profiles?
sfdc_ninjasfdc_ninja
I just recently ran into this same issue on a trigger that worked before.  Cannot seem to debug and find out why.  Did you find any resolution to this?
Lisa WalsakLisa Walsak
I'm hitting this issue too.  Any resolution?
Julie ConradJulie Conrad
I ran into this issue also... any solution?
Lisa WalsakLisa Walsak
We opened a case with support and this was the answer they gave:

The issue is with the permissions given to the particular profile for account name field (accountID).

While creating a new case we need to push account ID into database which is not allowed as per permissions.

account ID is readable only and we can not push the same into database, which is required part when we create a case.

Example - If we create a new case with field contact name(R/W) and account name(R only). When we insert the case with all field values, at backened server will check that account name is readable and hence would not take value and send NULL value which goes to trigger/class and cause issue.

However you may notice this will work for update operation because account name value is already in database.


This is what I ended up coding in the class for our situation:

        Set<Id> aSet = new Set<Id>();
        // user is coming from customer portal and account Id is not on the case yet
        if ( UserInfo.getUserType().equals(Constants.USER_TYPE_CUSTOMER) ) {
            User u = [select Contact.AccountId from User where Id = :UserInfo.getUserId()]; 
            for(Case c : cases){
                aSet.add(u.Contact.AccountId);
                c.AccountId = u.Contact.AccountId;
            }
        }else{
            for(Case c : cases){
                aSet.add(c.AccountId);
            }
        }

Hope that helps!