+ Start a Discussion
Edward Scott 5Edward Scott 5 

Trigger not firing when using dataloader

Hi,

I was just able to get this trigger to work yesterday with the help of the community. It updates a field on the opportunity object from the opportunity team member page. It works fine whe I create an opportunity or edit one but it doesn't work when I use data loader. I am new to apex code and I saw an article about first creating a set in order to get the trigger to be a bulk trigger but I am not sure how to do it.  Here is my code I was wondering if anyone could help me. 
Trigger updateAdOps on Opportunity (after update, after insert) {

  // Get Ad Ops team members & put in a map of <OpportunityId,AdOpsTeamMemberId>
  map<id,id> mOtms = new map<id,id>();
  list<OpportunityTeamMember> otms = new list<OpportunityTeamMember>([
      SELECT id,opportunityId,TeamMemberRole,UserId 
      FROM OpportunityTeamMember
      WHERE opportunityId IN :trigger.newmap.keyset()
        AND TeamMemberRole = 'Ad Ops'
      ]);

  For(OpportunityTeamMember otm :otms) {
    mOtms.put(otm.OpportunityId,otm.UserId);
  }

  // Re-aquire the Opportinities and Update them with the Ad Ops team member
  list<Opportunity> opportunitiesToUpdate = new list<opportunity>([SELECT id,Ad_Ops_Contact1__c FROM   Opportunity WHERE Id IN :trigger.newmap.keyset()]);
  for(Opportunity o :opportunitiesToUpdate) {
    if(mOtms.containsKey(o.id)){
      o.Ad_Ops__c = mOtms.get(o.id);
    }
  }

  if (util_utilities.alreadyExecuted != true) {
    util_utilities.alreadyExecuted = true;
    if(opportunitiesToUpdate.size()>0) {
      update opportunitiesToUpdate;
    }
  }

}

 
pconpcon
Have you monitored the Debug Logs to see if your trigger even fires.  My guess is that it is firing and something else is setting util_utilities.alreadyExecuted to true and it's skipping lines 24-29.
Edward Scott 5Edward Scott 5
I haven't. How do I check the debug logs? I'm an admin an I'm studying to get my masters in comp sci but I'm pretty new to apex code so this is all kinda new to me this is only the second trigger that I have written. I really appreciate all of your help.