You need to sign in to do that
Don't have an account?

rec.Owner.Name returning null in before update trigger
I am trying to update a text field with the owner's name everytime the owner is changed to one among a particular group of users. The new record's owner id is correctly returned in the debug log however the rec.owner.Name is returning null.
Can somebody help me understand what is the issue?
Can somebody help me understand what is the issue?
This is a known issue from salesforce side, to known more on this you can go ahead and check this link : http://www.michaelforce.org/recipeView?id=a0G30000006aQgCEAU .
But i can suggest you to do some custom logic for this on your trigger like this...
Map<String,String> idOwnerNameMap = new Map<String,String>();
//Query all active user and add id and Name to this map
//Query all queue and add id and Name to this map
for(Record rec : Trigger.new){
String OwnerName ;
// check that owner is a user (not a queue)
if((String)(rec.OwnerId).substring(0,3) == '005' ){
OwnerName = idOwnerNameMap.get(rec.OwnerId);
}
// check that owner is a queue
else if((String)(rec.OwnerId).substring(0,3) == '00G' ){
OwnerName = idOwnerNameMap.get(rec.OwnerId);
}
}
Regards,
Rajesh
All Answers
This is a known issue from salesforce side, to known more on this you can go ahead and check this link : http://www.michaelforce.org/recipeView?id=a0G30000006aQgCEAU .
But i can suggest you to do some custom logic for this on your trigger like this...
Map<String,String> idOwnerNameMap = new Map<String,String>();
//Query all active user and add id and Name to this map
//Query all queue and add id and Name to this map
for(Record rec : Trigger.new){
String OwnerName ;
// check that owner is a user (not a queue)
if((String)(rec.OwnerId).substring(0,3) == '005' ){
OwnerName = idOwnerNameMap.get(rec.OwnerId);
}
// check that owner is a queue
else if((String)(rec.OwnerId).substring(0,3) == '00G' ){
OwnerName = idOwnerNameMap.get(rec.OwnerId);
}
}
Regards,
Rajesh
SF should fix this issue. It feels wierd to waste a query when u can simply use the object relationship.