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
redavis13redavis13 

Having a problem selecting the ManagerId field from User object in Apex???

User mgr = [Select u.Managerid from User u where Id =: trigger.new[i].Opportunity_Owner__c];

 

this query returns the error message:

 

Save error: No such column 'Managerid' 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. Training/src/unpackaged/triggers UpdateOpportunity.trigger line 26 1263569168065 3293

But I can run the query in Eclipse against the schema query tool.

mtbclimbermtbclimber

Does this always happen or just sometimes? If not always is it user specific, i.e. admins don't hit it but regular or portal users do?

 

redavis13redavis13
It happens when saving the trigger. What is weird is that I reference this field in the User object in other triggers.
mtbclimbermtbclimber

So it's a compile error? That's interesting.  Can you put this logic in other triggers that are compiling OK with that field referenced?

 

BTW, your code as it's written above appears as though it might be in a loop which will likely cause some governor limit issues for you down the road.

 

redavis13redavis13

Yes, here is an instance of where I use this somewhere else:

 Account currentAccount = Trigger.new[i];

if(Trigger.old[i].OwnerId != Trigger.new[i].OwnerId || Trigger.old[i].Key_Rep__c != Trigger.new[i].Key_Rep__c){

User currentUser = [select Id, ManagerId from User where Id =: currentAccount.Ownerid];

currentAccount.Key_Rep__c = currentAccount.Ownerid;

if(currentUser.ManagerId != null){

currentAccount.Key_DOS__c = currentUser.ManagerId;

} else {currentAccount.Key_DOS__c = null;

}

}

mtbclimbermtbclimber

Does it still fail if you remove the aliasing from the query that is failing compile?, i.e. u.managerid -> managerId?

 

Either way, can you log a case with salesforce support please? I'd like to take a closer look at this.

 

Thanks,

redavis13redavis13

Here is what I ended up doing, used a "SET".

 

 if (Trigger.isUpdate ){

List<Lead> updatedLeads = New List<Lead>();

set<string> changedowners = new set<string>();

for(integer i = 0; i<trigger.new.size();i++){

if (trigger.new[i].OwnerId <> trigger.old[i].OwnerId) {

changedowners.add(trigger.new[i].Ownerid);updatedLeads.add(

trigger.new[i]);

}

}

if (changedowners.size() > 0) {

Map<ID,User> userMap = new Map<ID,User>([Select Id, ManagerId From User where IsActive = true and id in : changedowners]);

for (lead l : updatedleads){

if(userMap.containsKey(l.OwnerId)){l.Owner_Manager__c = userMap.

get(l.OwnerId).ManagerId;

} else {l.Owner_Manager__c =

null;

}

}

}

}

 

Thanks for all of the input!