When users tejdeep,then owner of opportunity should be changed with the name of related account owner?**

  • 2
    Can you be little specific and add relevant code snippet or explanation for what you need here ? – Mohith Shrivastava Jan 27 '14 at 7:04
  • 1
    Teja, please try to only use tags which are related to the question. Adding as much tags as you can does not help your question get answered faster. – Samuel De Rycke Jan 27 '14 at 7:47

You can change the owner of an opportunity to the owner of the associated account via a trigger. Assuming you just wanted to do this when the opportunity was created, it would simply be:

trigger bi_opportunity on Opportunity (before insert)
   // get the ids of all the accounts
   Set<Id> accIds=new Set<Id>();
   for (Opportunity opp : trigger.new)

   // retrieve the accounts and owners
   List<Account> accs=[select id, OwnerId from Account where id in :accIds];
   Map<Id, Account> accById=new Map<Id, Account>();

   // iterate the opportunities, updating the opportunity owner to the account owner
   for (Opportunity opp : trigger.new)
       // any logic about when to do this - i.e. only if the current owner matches a
       // particular id goes here
       if (null!=opp.AccountId)

I'm not sure what you mean by user=='tejeep', but whatever conditions you need can be inserted where the comment starting 'any logic' is present.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.