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
manhnt.bkitmanhnt.bkit 

[issue] Change Lead owner trigger before insert

Hello everyone,

I have a trigger change owner before insert a new lead record.

 

trigger trickOnLead on Lead (before insert) { 
   for (Lead ld : Trigger.new) {
         if(ld.testId__c != null ){
             ld.ownerid = ld.testId__c; 
         }
   }
}

 

 

-------------

I tested it through web-to-lead, and its successful.(on Monday, July 8th),

but today its not work anymore ?!

note that it only work for manual create a new record.

 

Thanks,

Manh

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
manhnt.bkitmanhnt.bkit

Thanks Souvik !

actually I have test  the value of " testId__c" in trigger by put it in email (for test).

Finally I came up with this code.

 

 

trigger trickOnLead on Lead (before insert, before update)
   for (Lead ld : Trigger.new) {
         if(ld.testId__c != null ){
             ld.ownerid = ld.testId__c; 
         }
   }
}

All Answers

souvik9086souvik9086

I didn't find any problem in the trigger. Make sure you have value in this field testId__c.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

manhnt.bkitmanhnt.bkit

Thanks Souvik !

actually I have test  the value of " testId__c" in trigger by put it in email (for test).

Finally I came up with this code.

 

 

trigger trickOnLead on Lead (before insert, before update)
   for (Lead ld : Trigger.new) {
         if(ld.testId__c != null ){
             ld.ownerid = ld.testId__c; 
         }
   }
}

This was selected as the best answer