You need to sign in to do that
Don't have an account?
kushagra gupta 23
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, countcontatcs: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGU
-------Getting this issue:Please guide:::I have started with some basics----------
"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, countcontatcs: execution of BeforeInsert
caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Trigger.countcontatcs: line 10, column 1: []"
--------------Trigger:-----------------------------------
trigger countcontatcs on Contact (before insert) {
for (contact c : trigger.new)
{ integer i =0;
account a = new account();
if (c.accountid == a.id)
{ i++;
a.contactcounter__c=i;
}
update a;
}
}
--------------test clsss----------------------
@isTest
public class countcontactstest {
static testmethod void validatecountcontacts()
{ list<account> acclist = new list<account>();
list<contact> conlist= new list<contact>();
for (integer i = 0 ; i<2; i++)
{
account a = new account (name ='test' + i, First_Name__c= 'testfirstname'+i, Last_Name__c='testlastname'+i);
for (integer j = 0 ; j<1 ; j++)
{
contact c = new contact();
c.LastName= 'lastcontactname'+i;
c.AccountId = a.id;
conlist.add(c);
}
acclist.add(a);
}
test.startTest();
insert acclist;
insert conlist;
test.stoptest();
}
}
"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, countcontatcs: execution of BeforeInsert
caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Trigger.countcontatcs: line 10, column 1: []"
--------------Trigger:-----------------------------------
trigger countcontatcs on Contact (before insert) {
for (contact c : trigger.new)
{ integer i =0;
account a = new account();
if (c.accountid == a.id)
{ i++;
a.contactcounter__c=i;
}
update a;
}
}
--------------test clsss----------------------
@isTest
public class countcontactstest {
static testmethod void validatecountcontacts()
{ list<account> acclist = new list<account>();
list<contact> conlist= new list<contact>();
for (integer i = 0 ; i<2; i++)
{
account a = new account (name ='test' + i, First_Name__c= 'testfirstname'+i, Last_Name__c='testlastname'+i);
for (integer j = 0 ; j<1 ; j++)
{
contact c = new contact();
c.LastName= 'lastcontactname'+i;
c.AccountId = a.id;
conlist.add(c);
}
acclist.add(a);
}
test.startTest();
insert acclist;
insert conlist;
test.stoptest();
}
}
Let me know if adding an insert statement helps
I recommend checking the following resources
https://help.salesforce.com/articleView?id=000332026&type=1&mode=1
https://developer.salesforce.com/forums/?id=906F0000000ApEjIAK
https://salesforce.stackexchange.com/questions/141288/error-when-update-missing-argument-id-not-specified-in-an-update-call