You need to sign in to do that
Don't have an account?
Soujanya Uppal 9
change contact owner on new record through trigger when industry = agriculture
Hi everyone!!
How to do with trigger?
Change contact owner on new record through trigger when industry = agriculture.
How to do with trigger?
Change contact owner on new record through trigger when industry = agriculture.
As you state that you want to change the owner field of contact records, I assume that the records are already inserted.
So in this case
- Create a trigger on the Contact object for after insert
- Inside the trigger, write logic to find all inserted records ( basically Trigger.newMap )
- Filter out records having industry = agriculture.
- Change the owner based on your business requirement ( or possibly with a helo of custom setting)
Hope this helpsThis Code is fit for your requirement try this once
Here alias name 'sthri' is in my user list you can write your user name whose you want assign that record..
trigger userForAccount on Contact (before insert) {
User u = [SELECT Id, Name FROM User WHERE alias = 'sthri'];
for(Contact con : Trigger.new){
if(industry == agriculture){
con.ownerId = u.id;
}
}
}
who created the record. OwnerId : ID of the User who has been assigned to work this record. If you update this field, the previous owner's access becomes Read Only or the access specified in your organization-wide,createdby is nothing but ownerid
trigger contacrTrigger on Contact (afetr insert) {
User u = [SELECT Id, Name FROM User WHERE Name= 'padma'];
list<contact> lstcon = [SELECT Id, Name FROM contact WHERE Id in:Trigger.new'];
for(Contact con : lstcon ){
if(con.industry == 'agriculture'){
con.createdbyId = u.id;
}//end if
}//end for
}// end Trigger
Hope This helpful
Thanks Records
Vaani