You need to sign in to do that
Don't have an account?
Ashwini Patil 32
DML
Hello,
I am trying to update account owner on the account object using DML. Below is my basic code, when executed, shows the Log as Successful. When I check on the record in Salesforce it shows the old owner, not the updated owner. I am not sure what's going wrong. Any help would be apprecitated.
User u = [SELECT Id, Name, IsActive FROM User WHERE username = 'test@test.com];
List<Account> myList = [SELECT Owner.id, Owner.Name FROM Account where Owner.Name = 'ABC'];
for(Account acc: myList){
acc.Owner.Id = u.Id;
}
Update myList;
Thanks!
I am trying to update account owner on the account object using DML. Below is my basic code, when executed, shows the Log as Successful. When I check on the record in Salesforce it shows the old owner, not the updated owner. I am not sure what's going wrong. Any help would be apprecitated.
User u = [SELECT Id, Name, IsActive FROM User WHERE username = 'test@test.com];
List<Account> myList = [SELECT Owner.id, Owner.Name FROM Account where Owner.Name = 'ABC'];
for(Account acc: myList){
acc.Owner.Id = u.Id;
}
Update myList;
Thanks!
Please try the below code and let me know if it works for you. Hope this helps.
Thanks,
Nagendra
Please try the below code:
The only change is : Instead of 'owner.Id' we need to use 'ownerId'.
Hope this will be helpful.
Thanks
Bhargavi.