You need to sign in to do that
Don't have an account?
Karthikeyan Kannan
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
I am Updating Some fields in a SiteContracts__c Object from Engineer_Checklist__c object , while performing this Operation getting the Above mentioned Error, Can any one suggest me where should I Specify the ID and How ?
Here is my Code:
public List<id> sitecontractids = new List<id>();
public List<Engineer_Checklist__c> ssnewList = new List<Engineer_Checklist__c>();
public List<SiteContracts__c> scnewlist = new List<SiteContracts__c>();
public List<SiteContracts__c> scList =[SELECT id, name From SiteContracts__c LIMIT 200];
for(SiteContracts__c scnewid :scList ){
sitecontractids.add(scnewid.id);
}
ssnewList =[Select Id, X6L_Water_Qty__c, X9L_Water_Qty__c, X3L_Water_Mist_Qty__c, X6L_Water_Mist_Qty__c, X9L_Water_Mist_Qty__c
From Engineer_Checklist__c
Where Fire_Extinguisher_Service_complete__c=true AND Site_Contract__c !=NULL AND
Site_Contract__c IN :sitecontractids Order By lastmodifieddate desc LIMIT 200];
for(Engineer_Checklist__c ssli:ssnewList)
{
SiteContracts__c newsc = new SiteContracts__c();
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;
Here is my Code:
public List<id> sitecontractids = new List<id>();
public List<Engineer_Checklist__c> ssnewList = new List<Engineer_Checklist__c>();
public List<SiteContracts__c> scnewlist = new List<SiteContracts__c>();
public List<SiteContracts__c> scList =[SELECT id, name From SiteContracts__c LIMIT 200];
for(SiteContracts__c scnewid :scList ){
sitecontractids.add(scnewid.id);
}
ssnewList =[Select Id, X6L_Water_Qty__c, X9L_Water_Qty__c, X3L_Water_Mist_Qty__c, X6L_Water_Mist_Qty__c, X9L_Water_Mist_Qty__c
From Engineer_Checklist__c
Where Fire_Extinguisher_Service_complete__c=true AND Site_Contract__c !=NULL AND
Site_Contract__c IN :sitecontractids Order By lastmodifieddate desc LIMIT 200];
for(Engineer_Checklist__c ssli:ssnewList)
{
SiteContracts__c newsc = new SiteContracts__c();
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;
You need to pass id for which record you want to update.
please use the below part of code changes in your 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;
Thanks
Anil.B
All Answers
Use insert scnewlist;
instead of update scnewlist;
You need to pass id for which record you want to update.
please use the below part of code changes in your 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;
Thanks
Anil.B
I need to update existing records and I don want to insert a new record into the Object.
Do the changes in your code with the code i have given it will work for updating the existing records.
Thanks
Anil.B
and specify Site_Contract__c field in your query
Thank you, that works fine for me and can u suggest me how to use set to avoid Duplicate Id's, I am little confused about set.
@anilbathula@ (https://waterfilterinsight.com/best-faucet-water-filter-reviews/)
Thank you, that works good for me. Could you maybe explain how to use set to eliminate duplicate IDs? I'm not sure what set is.