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
Sid LightningSid Lightning 

Apex trigger /Workflow to Update opportunity owner when field on user changes ?

Hi,

I have a field 'Site' on Users, which gets mapped to Opportunity once the user from that site creates an opportunity.

So , lets say if a user from Site A creates an opportunity , Opportunity will be stamped with Site A.


Now sometimes, there are transfers, so user from Site A gets transferred to Site B, I want to write an apex trigger , whenver a user gets transfferd from Site A to Site B. for All the opportunites created by him  , oppotunity owner should change to Site A manager..( sort of handover)  , Site A store managers role is "Site A".

How can we achieve this
Best Answer chosen by Sid Lightning
Martha VMartha V
To transfer the opportunities to the manager, you shouldn't use a trigger, but rather a button to run a process ( a flow, or apex code). The better choice would be a flow, and this seems to be a good case for it. 
The trigger could be the one to add the Site field to the opportunity, but you could also do this easier with Process Builder.

All Answers

Martha VMartha V
To transfer the opportunities to the manager, you shouldn't use a trigger, but rather a button to run a process ( a flow, or apex code). The better choice would be a flow, and this seems to be a good case for it. 
The trigger could be the one to add the Site field to the opportunity, but you could also do this easier with Process Builder.
This was selected as the best answer
Sid LightningSid Lightning
Thank Matha.

Can you please help me with other questions, that I have posted
Martha VMartha V
Sure thing, I will read your questions and see if I can help :-)
Martha VMartha V
Sid, I looked at your only other question that hasn't been solved and is about doing a REST or POST call. I am not very familiar with that procedure. There is a trail or a module that teaches it, you might find that helpful. I did the module/trail, but I haven't have to use it as of yet so I have no experience. 

Martha