You need to sign in to do that
Don't have an account?
Ludivine
Is it possible to Update the Name of the Contract Owner?
Hi,
When the Owner of an account has been changed , I would like to change as well the owner on the related Contract.
I wrote this trigger but it gives me an error, Does someone see where is the issue?
Many thanks for your time.
[Code]
trigger ChangeAccountOwnerOnContract on Account(after insert,After update){
for(Account Acc :Trigger.new){
List<Contract> C = [select Owner.Id from Contract where Account.Id = :Acc.Id];
for (Contract Ctrct : C)
{
Ctrct.Owner.Id = Acc.Owner.Id ;
}
update C;
}
}
[/code]
Error: Apex trigger ChangeAccountOwnerOnContract caused an unexpected exception, contact your administrator: ChangeAccountOwnerOnContract: execution of AfterUpdate
caused by: System.DmlException: Update failed. First exception on row 0 with id 80020000000vULAAA2; first error: INVALID_FIELD, Cannot specify both an external ID reference Owner and a salesforce id, OwnerId: []: Trigger.ChangeAccountOwnerOnContract: line 14, column 1
When the Owner of an account has been changed , I would like to change as well the owner on the related Contract.
I wrote this trigger but it gives me an error, Does someone see where is the issue?
Many thanks for your time.
[Code]
trigger ChangeAccountOwnerOnContract on Account(after insert,After update){
for(Account Acc :Trigger.new){
List<Contract> C = [select Owner.Id from Contract where Account.Id = :Acc.Id];
for (Contract Ctrct : C)
{
Ctrct.Owner.Id = Acc.Owner.Id ;
}
update C;
}
}
[/code]
Error: Apex trigger ChangeAccountOwnerOnContract caused an unexpected exception, contact your administrator: ChangeAccountOwnerOnContract: execution of AfterUpdate
caused by: System.DmlException: Update failed. First exception on row 0 with id 80020000000vULAAA2; first error: INVALID_FIELD, Cannot specify both an external ID reference Owner and a salesforce id, OwnerId: []: Trigger.ChangeAccountOwnerOnContract: line 14, column 1
contact con =[select id,ownerid from contact where id='003F000000pdYZy'];
con.ownerid='005F0000002D0t3';
update con;
All Answers
https://developer.salesforce.com/forums?id=906F00000008rCsIAI
thanks for your reply.
I changée owner.id by Owner. I changed the account Owner on Account,The error Is not showing anymore but the Contract Owner has not been updated on the related Contract :( Any ideas?
contact con =[select id,ownerid from contact where id='003F000000pdYZy'];
con.ownerid='005F0000002D0t3';
update con;
I have changed Owner by OwnerId and it is working now!
Many thanks for your great support!