+ Start a Discussion

Save error: Invalid field AccountId for SObject User

for (User u : Trigger.new) {

AccountShare share = new AccountShare();

share.AccountId = u.AccountId;


 Why is the IDE telling me that User doesn't have an AccountId field?


User object 

If you go to your schema in the eclipse IDE and go down to The User object and expand the fields branch you will see the available fields to use for the User object. My user object does not have an AccountId field. My guess is thats the IDE is telling you that.
I think you have to have Customer Portal enabled in order for the field to be visible in your org.  Perhaps that's why you don't see it.  

I actually have another sandbox that has the customer portal enabled and I do not see it in that schema in the force.com IDE either. Are you seeing it as an available field?

Do you need to go through contact id? Since a customer portal user comes from a contact which is linked to an account.


Sorry I cannot be of any help just thought you could check your schema to see if it is indeed an available field that is related to the object you are trying to make use of. But the way i look at it is if you look at your customer portal user record and there is an account lookup field there then that field would be usable for the User object but if there is not then it probably isnt.  

Message Edited by MSVRad on 02-11-2010 01:49 PM

Both the force.com IDE and SoqlXplorer can query it, which means it's available through the WS API.  Also, this link to the documentation User object shows that AccountId is a field on the User object.


It may be an Apex bug.  In any case, I just worked around it. 


Hi jeremy, i am facing the same issue. Whats the workaround?





I don't recall. I probably grabbed User.ContactId and queried for the Contact's AccounId field.