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
jwanjwan 

Trigger not updating object

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); } } } }

 

 

 

James_AdapxJames_Adapx

Maybe missing an update call?

 

update object;

 

 

 

--James 

Message Edited by James_Adapx on 02-13-2009 01:29 PM
jrotensteinjrotenstein

You don't need to use an update command since you're only modifying data in Trigger.new.

Are you seeing those last two debug messages in your log?