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
Yogesh Malbhage 18Yogesh Malbhage 18 

Why can't I access User.ContactId from a lightning component?

I can't get a lightning component that references User.ContactId to compile. Here's my code:
TestComponent.cmp
<aura:component controller="TestController"> </aura:component>


TestController.apxc
public with sharing class TestController { public void testMethod1 () { User u = [SELECT ID, ContactId FROM User LIMIT 1]; } }

When I compile the Apex class, it compiles just fine. But when I subsequently compile the lightning component, I get this error:
Failed to save TestComponent.cmp: Invalid definition for null:TestController: SELECT ID, ContactId FROM User LIMIT 1 ^ ERROR at Row:1:Column:12 No such column 'ContactId' on entity 'User'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.: Source
I know it's ContactId because everything compiles when I remove that field from the query. Also, when I remove the controller field from the component, it compiles just fine.
I know User.ContactId exists, and the Apex part compiles fine. But for some reason, the lightning component thinks that User.ContactId doesn't exist.
Why is it doing this, and how can I fix it?
Yogesh Malbhage 18Yogesh Malbhage 18
Any field from User is giving the same error