You need to sign in to do that
Don't have an account?

Hi, I have a use case.I have three objects Student,Account and Contact."Student is parent to Account and Account is parent to Contact.When ever i update Tenure field in contact,Students "Tenure" field should also be updated.I am having issues wth code.
Hi, I have a use case.I have three objects Student,Account and Contact."Student is parent to Account and Account is parent to Contact.When ever i update Tenure field in contact,Students "Tenure" field should also be updated.I am having issues wth code.When I am tring to update a field in contact this isthe error, I am getting.<<< ERROR : Review the following errors
StudentTenure: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.StudentTenure: line 14, column 1 :>>>
Program:
trigger StudentTenure on Contact (After Update) {
List<Student__c> stulst = new List<Student__c>();
List<Contact> cst = new List<Contact>();
cst = [SELECT id,Name,Tenure__c,Account.Student__r.Tenure__c FROM Contact WHERE id IN :Trigger.old];
System.debug('Data is cst: '+cst);
for(Contact c : cst){
Student__c s = new Student__c();
if(c.Tenure__c == 'OLD'){
s.Tenure__c = 'OLD';
}
stulst.add(s);
}
update stulst;
}
StudentTenure: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.StudentTenure: line 14, column 1 :>>>
Program:
trigger StudentTenure on Contact (After Update) {
List<Student__c> stulst = new List<Student__c>();
List<Contact> cst = new List<Contact>();
cst = [SELECT id,Name,Tenure__c,Account.Student__r.Tenure__c FROM Contact WHERE id IN :Trigger.old];
System.debug('Data is cst: '+cst);
for(Contact c : cst){
Student__c s = new Student__c();
if(c.Tenure__c == 'OLD'){
s.Tenure__c = 'OLD';
}
stulst.add(s);
}
update stulst;
}
try below code.
All Answers
To call the Id,
if(c.Tenure__c == 'OLD'){
s.Tenure__c = 'OLD';
}
Here you have given the values not mention the Id to match which record to be store values.For that you have assign the Id for the Record So
write the code like this in the below code
for(Engineer_Checklist__c ssli:ssnewList)
{
SiteContracts__c newsc = new SiteContracts__c();
newsc.id=ssli.Site_Contract__c; //i hope this is the relation ship field between both the objects
newsc.X6L_Water__c=ssli.X6L_Water_Qty__c;
newsc.X9L_Water__c=ssli.X9L_Water_Qty__c;
newsc.X3L_Water_Mist__c=ssli.X3L_Water_Mist_Qty__c;
newsc.X6L_Water_Mist__c=ssli.X6L_Water_Mist_Qty__c;
newsc.X9L_Water_Mist__c=ssli.X9L_Water_Mist_Qty__c;
scnewlist.add(newsc);
}
update scnewlist;
In the above code it to be mention in the Bold character.
Here you will assign the student id =the lookup field name.
Hope this Helps!
Thanks,
K.Kamala,
Sweet Potato Tec.
try below code.