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
bhupal reddy 7bhupal reddy 7 

How to change owner field of opportunity to other userId (Ex. Sales Team) After record is getting created?

Sai PraveenSai Praveen (Salesforce Developers) 
hi,

Can you confirm if you need Trigger logic or Flow?

Thanks,
 
bhupal reddy 7bhupal reddy 7
I need to achieve it through Trigger only!
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Bhupal,

You can use trigger simialar to thos. Here I am assing one of the user in sasss profile as owner.
 
trigger ChangeOwner on Opportunity (before insert) {
    
    User us=[select id,name,ProfileId from User where Profile.name='sasss' limit 1];
    for(Opportunity opp:Trigger.new){
        opp.ownerid=us.id;
    }

}
Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
 
bhupal reddy 7bhupal reddy 7
Thank you So Much Praveen It is working !!!

I have one more query Like ===>>

Is it Possible to use share Objects to change Owners  of the Record??