You need to sign in to do that
Don't have an account?
jungleee
Traversing Owner field in trigger
Hi All,
I am aware of the fact that we cannot traverse on the ownerId field in the formula field. But I came across a similar problem in triggers. In the below class I am passing a map from the trigger to a class as below
//passing newMap to the below method. public static void someMethod(map<id, opportunity> newOppMap){ list<opportunity> oppty = newOppMap.values(); //iterating thru the list of opportunity. for(opportunity opp: oppty){ if(opp.owner.isportalEnabled){//I am unable to fetch the CORRECT value of isportalEnabled. it always returns False for all the owners. .....some code.... } } }
Any idea why this is happening??
Workaround: to create a map of user based on the owner and pass the the id to the map to fetch the correct value.
Regards
Sam
The full object graph isn't populated when you hit a trigger, so while the OwnerId will be populated, the Owner reference won't be, so any attempt to access the related object's fields will return null.
Thus regardless of the type of lookup (even when polymorphic like the owner), you'd still need to retrieve the related objects.
All Answers
The full object graph isn't populated when you hit a trigger, so while the OwnerId will be populated, the Owner reference won't be, so any attempt to access the related object's fields will return null.
Thus regardless of the type of lookup (even when polymorphic like the owner), you'd still need to retrieve the related objects.
You could try nesting a loop like this going through each oppy and then the owner, it adds another query though, but it might be a good way to check your code.
Might want to run a few queries in the workbench, just to check and make sure you are referencing correctly, and that you are referencing portal users.
--KC
This is quite a bad idea - nesting soql queries inside for loop means they aren't bulk-safe - more than 100 records and you will blow governor limits.
There's a discussion on this at:
http://wiki.developerforce.com/page/Best_Practice:_Avoid_SOQL_Queries_Inside_FOR_Loops
Thanks Bob for the clear explaination.
The workaround that I have uesd is this:
Hope it helps!!
Regards
Sam