Public static void opptyownermanagerupdate(Opportunity[] Opptylist)
{
List<Opportunity> Opptylists = new List<Opportunity>();
List<Opportunity> opptyToUpdate =new List<Opportunity>();
Set<id> ownerid = new Set<id>();
For(Opportunity op :Opptylists)
{
if(op.StageName=='ClosedWon'&& op.Order_Complete__c)
{
If(ownerid != null && !ownerid.isEmpty())
{
ownerid.add(op.owner.id);
opptytoUpdate.add(op);
}
}
}
Map<Id, string> userMap= new Map<Id, string>();
For(User oppOwner : [Select Id, Manager.Name from User where Id IN :ownerid ])
{
userMap.put(oppOwner.Id, oppOwner.Manager.Name);
}
For(Opportunity op: Opptylists)
{
op.Timestamped_Manager__c = usermap.get(op.owner.id);
}
}
I have written the code above to update the Timestamped Manager
field with the Opportunity Owner's manager name, but it is getting updated with Opportunity Owner's Id instead. What correction needs to be done here?
op.ownerId
would be better thanop.owner.id
as related objects are not populated in triggers. But as posted, this class will never do anything because it is iterating over the emptyOpptylists
rather than theOpptylist
that is passed in. Can you check that in the code you are running and update your question?!ownerid.isEmpty()
? Alsoownerid != null
it's always the case since you're instantiating it above -Set<id> ownerid = new Set<id>();
so you don't have to check for that.