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
SFAdmin5SFAdmin5 

trigger to update owner to record creator

i need a trigger that updates a custom object record's Owner field to be the record's creator when the record is marked as "Payment Processed" in a custom picklist field called "Billing Status".  so basically whenever a record is updated to that value in that picklist field, the trigger should simply switch the owner back to record creator.  Is this possible?

nandurinanduri

Yes this is possible, sample non bulk trigger -

 

trigger UpdateOwner on CustomObject__c (before Update) {   

if((trigger.new[0].PicklistField__c == 'Payment Processed') && (trigger.old[0].PicklistField__c != 'Payment Processed')){       trigger.new[0].OwnerId = trigger.new[0].CreatedById ;

         }

}