You need to sign in to do that
Don't have an account?
Shubhangi Jadhav
Getting error in Account contact relation : System.DmlException: Insert failed. First exception on row 0 with id 0033N00000Ny93pQAB; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Code is:
@isTest
public static void testMethod4(){
Account acc1 =new Account();
acc1.Name='Managal';
insert acc1;
Account acc2 =new Account();
acc2.Name='Managala';
insert acc2;
contact con=new contact();
con.lastname='Jyoti';
con.firstname='Savalgi';
con.AccountId=acc1.id;
con.Tet_Contact_Pid__c = '060587-12949';
insert con;
AccountContactRelation Acctcr=
new AccountContactRelation(AccountId=acc2.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
insert Acctcr;
Acctcr.Tet_IsPrimaryContact__c= True;
update con;//Updated Primary to contact Sam
Account acc3 =new Account();
acc3.Name='Bibhu';
insert acc3;
Account acc4 =new Account();
acc4.Name='Bibhudutta';
insert acc4;
contact con1=new contact();
con1.lastname='Ankit';
con1.firstname='Savalgi';
con1.AccountId=acc3.id;
con1.Tet_Contact_Pid__c = '200568-13106';
insert con;
AccountContactRelation Acctcr1=
new AccountContactRelation(AccountId=acc4.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
insert Acctcr1;
Acctcr1.Tet_IsPrimaryContact__c= True;
update con1;//Updated Primary to contact Ankit
con.Tet_Contact_Pid__c=con1.Tet_Contact_Pid__c;
update con;
system.debug('Value of 2nd contact is:' +con1.Tet_Contact_Pid__c);
}
@isTest
public static void testMethod4(){
Account acc1 =new Account();
acc1.Name='Managal';
insert acc1;
Account acc2 =new Account();
acc2.Name='Managala';
insert acc2;
contact con=new contact();
con.lastname='Jyoti';
con.firstname='Savalgi';
con.AccountId=acc1.id;
con.Tet_Contact_Pid__c = '060587-12949';
insert con;
AccountContactRelation Acctcr=
new AccountContactRelation(AccountId=acc2.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
insert Acctcr;
Acctcr.Tet_IsPrimaryContact__c= True;
update con;//Updated Primary to contact Sam
Account acc3 =new Account();
acc3.Name='Bibhu';
insert acc3;
Account acc4 =new Account();
acc4.Name='Bibhudutta';
insert acc4;
contact con1=new contact();
con1.lastname='Ankit';
con1.firstname='Savalgi';
con1.AccountId=acc3.id;
con1.Tet_Contact_Pid__c = '200568-13106';
insert con;
AccountContactRelation Acctcr1=
new AccountContactRelation(AccountId=acc4.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
insert Acctcr1;
Acctcr1.Tet_IsPrimaryContact__c= True;
update con1;//Updated Primary to contact Ankit
con.Tet_Contact_Pid__c=con1.Tet_Contact_Pid__c;
update con;
system.debug('Value of 2nd contact is:' +con1.Tet_Contact_Pid__c);
}
Error is in insert in below block in your code.
you are again inserting con record despite inserting it above in your code. Please mark this as the best answer if it solves your concern.
All Answers
Error is in insert in below block in your code.
you are again inserting con record despite inserting it above in your code. Please mark this as the best answer if it solves your concern.
I got the mistake.
Thank you so much for your reponse.
Again getting error for Updating value of PID:
Error:System.DmlException: Insert failed. First exception on row 0 with id 0033N00000Ny93pQAB; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
con1.Tet_Contact_Pid__c=con.Tet_Contact_Pid__c;
update con1;
system.debug('Value of 2nd contact is:' +con1.Tet_Contact_Pid__c);
I want to update same PID for con2 as Con1