You need to sign in to do that
Don't have an account?
Soujanya Uppal 9
i want to change owner through trigger on new record when industry = agriculture
i want to change owner through trigger on new record when industry = agriculture else shows error
Please anyone give me code for this
i have tried this much
trigger changeownerTrigger on Account (before insert) {
for(Account ac: trigger.new){
if(ac.Industry=='Agriculture')
}
}
Please anyone give me code for this
i have tried this much
trigger changeownerTrigger on Account (before insert) {
for(Account ac: trigger.new){
if(ac.Industry=='Agriculture')
}
}
if(trigger.isBefore && trigger.isInsert )
{
for(Account ac: trigger.new){
if(ac.Industry=='Agriculture'){
ac.OwnerId = '0055g00000Ai5NfAAS'; // Here give the User Id to which owner the record has to assign
}
}
}
}
You can get the User Id from the URL of the User page also.
Kindly, check this below link it may help in finding the User Id..
https://help.salesforce.com/s/articleView?id=000312782&type=1
If it worked kindly mark it as best answer and Like it.
Thank you.,
else
{
//Error statement example., it can be in your requirement as below
ac.Industry.addError('Error Message');
}
Thank you.
Use this code for Trigger : you can get reference from this for getting User Id :
https://help.salesforce.com/s/articleView?id=000312782&type=1
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
Please try the below code:
Don't hardcode the user id inside trigger... You query the user id based on name or alias or username from user object....
Thanks,
Maharajan.C