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
steve456steve456 

Simple---Very Uregent..pls help


    for(Ordr__c o : Trigger.new)
    {     
      //record created by manager, assign ownership to employee
        if(o.Employee__c!=null)
      {
        if(employeeMap.get(o.Employee__c).User_Name__c==null)
        {
               o.OwnerId=employeeMap.get(o.Employee__c). State__r.Mkt__r.AGM__c  ;
        }

 

What i am basically doing is i have an order in which there is an employee field which is a look up to employee  and employee is look up to user

 

When employee field is nul in an order the owner of the order should be assigned to the market agm

 

When  i am trying to make the employee field blank and save its not getting updated....Could you say where shuld i make a change

Alexander_EAlexander_E

It would be a little easier, if you show us your query with all related objects and releated fields.

vishal@forcevishal@force
Hey Steve, can you post the whole code please?
steve456steve456

trigger OrderEmployeeAndOwner on Ordr__c (before insert,before update) {
   String errMessage = 'No Employee was found for user:'+Userinfo.getName();    
    Set<ID> employeeIds=new Set<Id>();
    for(Ordr__c o : Trigger.new)
    {
      if(o.Employee__c!=null)
      {
        employeeIds.add(o.Employee__c);
      }
    }

Map<Id,Employee__c> employeeMap=new Map<Id,Employee__c>([Select Id, User_Name__c,State__r.Mkt__r.AGM__c
                    from Employee__c Where Id in:employeeIds and User_Name__c!=null]);

for(Ordr__c o : Trigger.new)
    {     
      //record created by manager, assign ownership to employee
        if(o.Employee__c!=null)
      {
        if(employeeMap.get(o.Employee__c).User_Name__c==nu​ll)
        {
               o.OwnerId=employeeMap.get(o.Employe​e__c). State__r.Mkt__r.AGM__c  ;
        }

      else

       {}

Ritesh AswaneyRitesh Aswaney

You're filtering out Employee Records where the User_Name is NULL in your SOQL Query

Map<Id,Employee__c> employeeMap=new Map<Id,Employee__c>([Select Id, User_Name__c,State__r.Mkt__r.AGM__c
                    from Employee__c Where Id in:employeeIds and User_Name__c!=null]);

 

Naturally,

if(employeeMap.get(o.Employee__c).User_Name__c==nu​ll)

will never be true therefore, as there isn't an Employee Record with a NULL User_Name__c thanks to your query above.

 

steve456steve456

 if(employeeMap.get(o.Employee__c)==null)
          {
            o.OwnerId=employeeMap.get(o.Employee__c).State__r.Mkt__r.AGM__c;
                        
          }  

 

 

 

the original query is this way.

steve456steve456

What i am basically doing is i have an order in which there is an employee field which is a look up to employee  and employee is look up to user

 

When employee field is nul in an order the owner of the order should be assigned to the market agm

 

When  i am trying to make the employee field blank and save its not getting updated....Could you say where shuld i make a change

 

 

 

Ritesh AswaneyRitesh Aswaney

I'd say get rid of the User_Name__c != null in your SOQL Query.

 

So,

Map<Id,Employee__c> employeeMap=new Map<Id,Employee__c>([Select Id, User_Name__c,State__r.Mkt__r.AGM__c
                    from Employee__c Where Id in:employeeIds ]);

steve456steve456

I did that way but its not getting upsdated