• jwan
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

I'm creating my first trigger, and I can't get it to update the custom object.

 

Essentially the trigger uses the "Request Type" drop down, finds a Scope matching that field, and populates two fields on the request.  In my testing it finds the scope correctly, but does not update the Request custom object.

 

Is there something I'm forgetting?

 

Thanks,

 

Jeremy

 

 

trigger setScope on Request__c (before insert, before update) { //NOTE: This Trigger will not execute during bulk updates if (Trigger.new.size() > 1) return; for (Request__c r : Trigger.new) { Request__c oldR; if ((r.Record_Type__c != null && (r.Scope_Name__c == '' || r.Scope_Name__c == null) && (r.Scope_Description__c == '' || r.Scope_Name__c == null)) || (Trigger.IsUpdate)) { System.Debug('Matched Criteria'); if (Trigger.IsUpdate) { System.Debug('Update'); oldR = Trigger.oldMap.get(r.Id); if (r.Record_Type__c == oldR.Record_Type__c) System.Debug('Update: Record Type has not changed'); continue; } Scope__c Scope; Scope = [ SELECT Id, Name, Description_Scope__c FROM Scope__c WHERE (Scope__c.Name = :r.Record_Type__c) LIMIT 1]; if (Scope != null) { System.Debug('Found Scope ' + Scope.Name); r.Scope_Name__c = Scope.Name; r.Scope_Description__c = Scope.Description_Scope__c; System.Debug('Scope ' + r.Scope_Name__c); } } } }

 

 

 

  • February 13, 2009
  • Like
  • 0