You need to sign in to do that
Don't have an account?
AlecS
Assigning an Opportunity to another User through trigger
I have written a trigger on Opportunity that creates another copy of the Opportunity at close time for renewal business.
However, this renewal opportunity should be owned by another user, let's say, Alec Sewart.
I have tried all these codes, but they don't work. How can I assign all renewal opportunity to Alec Stewart through trigger.
//option 1: opp.OwnerId = [SELECT Id, name FROM User WHERE Name = 'Alec Stewart'].id; //option 2: opp.Owner.Name = 'Alec Stewart'; //option 3: opp.Owner.FirstName = [select FirstName from User where name = 'Alec Stewart'].FirstName; opp.Owner.LastName = [select LastName from User where name = 'Alec Stewart'].LastName;
Thanks.
It is definitely option 1; you need to set OwnerId.
Your error is that the SOQL query returns a list and you need to reference an element of that list:
of course, you will need to bulkify your trigger as many oppos could get closed in a batch and also handle queryExceptions where you can't find the renewal owner
All Answers
It is definitely option 1; you need to set OwnerId.
Your error is that the SOQL query returns a list and you need to reference an element of that list:
of course, you will need to bulkify your trigger as many oppos could get closed in a batch and also handle queryExceptions where you can't find the renewal owner
Thank you, option 1 worked.