Developer console updates current user’s User record

We have noticed that Developer Console does some kind of an update on the current user’s User record. When that happens, our User trigger is invoked, but with what seems limited permissions, and we get an exception emailed to us from Salesforce saying the following:

“No such column ‘FirstName’ 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.”

The error references a line with the simple query:

List<User> lookup = [select FirstName, LastName, Region__c, UserPreferencesApexPagesDeveloperMode from User where Id =: userId limit 1];

How weird is that? We haven’t pinpointed exact action in the developer console that causes this.

Answer

The developer console creates and manages IDEWorkspaces to keep track of open files, exec anon scrips, queries, etc. There is a field on User called “workspaceId” which is only exposed in the Tooling API. This field is used to keep track of the users current workspace. When you open the developer console for the first time or when you switch to a different workspace, the developer console updates the workspaceId field on user.

Triggers and validation rules shouldn’t be fired if that is the only field being updated because it is a tooling only field. The fact that yours is being fired is a bug. I would file a case with Salesforce.

The reason why you are getting the query exception, is because only a few fields are exposed in tooling. If any other fields are queried for inside of a tooling API context, i.e. your trigger fired by a tooling API update, you will get an error like that. One way to see the exposed fields in tooling is to look at your tooling.wsdl by going to Setup -> Develop -> API -> Generate Tooling WSDL.

<xsd:complexType name="User">
    <xsd:complexContent>
        <xsd:extension base="tns:sObject">
            <xsd:sequence>
                <xsd:element name="DelegatedUsers" minOccurs="0" type="tns:QueryResult" nillable="true"/>
                <xsd:element name="ManagedUsers" minOccurs="0" type="tns:QueryResult" nillable="true"/>
                <xsd:element name="UserPreferences" minOccurs="0" type="tns:QueryResult" nillable="true"/>
                <xsd:element name="WorkspaceId" minOccurs="0" type="tns:ID" nillable="true"/>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

Attribution
Source : Link , Question Author : Kirill Yunussov , Answer Author : Thomas

Leave a Comment