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
jeremyyjeremyy 

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 

MSVRadMSVRad
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.
jeremyyjeremyy
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.  
MSVRadMSVRad

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
jeremyyjeremyy

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. 

SidharthSidharth

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

 

Thanks

Sid

jeremyyjeremyy

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