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
vijaya Pepakayalavijaya Pepakayala 

I wnat to change A record owner when an new record is created ? how can i changed?

i want to write a trigger when an Account new record is created The industry is equal to Education It will Assign Another user The record owner get Changed
AnkaiahAnkaiah (Salesforce Developers) 
Hi Vijaya,

Which user it needs to be assigned.?

Thanks!!
AnkaiahAnkaiah (Salesforce Developers) 
Hi Vijaya,

Try with below code.
trigger Accountownerchange on account (before insert, before update){
//query which user you want to assign
user userid = [select id from user where Name ='test user' limit 1];

for(Account acc:trigger.new){
if(acc.industry !=tigger.oldmap.get(acc.industry) && acc.industry =='Education'){

acc.ownerId = userid;

}
}
}
if this helps, Please mark it as best answer.

Thanks!!
 
vijaya Pepakayalavijaya Pepakayala
it was showing variable doesnot exist and illigel Assighnment for user to id