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
Soujanya Uppal 9Soujanya Uppal 9 

change owner through custom label?

hi everyone,

how to change owner on new record on account through the custom label in trigger????

I have done through this-

trigger changeownerTrigger on Account (before insert) {
    
    user u= [select id, name from user where Alias='ragh'];
    for(Account ac: trigger.new){
            
            if(ac.Industry=='Agriculture'){
                ac.ownerid=u.id;
                
                
            }
           
        }
  
    
}
Maharajan CMaharajan C
Hi Soujanya,

Please try the below code:
 
trigger changeownerTrigger on Account (before insert) {
    
	string aliaslabel = system.Label.YOUR_CUSTOM_LABEL_NAME; 
    List<user> u= [select id, name from user where Alias=:aliaslabel limit 1];
    for(Account ac: trigger.new){
            if(ac.Industry=='Agriculture'){
				if(!u.isEmpty())
					ac.ownerid=u[0].id;                
            }
           
        }
}

Thanks.
Maharajan.C
Soujanya Uppal 9Soujanya Uppal 9
what is custom label name here and how to give?