1

I am getting this Error:

Initial term of field expression must be a concrete SObject: LIST

while Executing the Following code through Execute Anonymous:

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> newsc = 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,
                           X2L_AFFF_Qty__c, X3L_AFFF_Qty__c, X6L_AFFF_Qty__c, X9L_AFFF_Qty__c, X2KG_CO2_Qty__c, X5KG_CO2_Qty__c,
                           X1_KG_Dry_Powder_Qty__c, X2KG_Dry_Powder_Qty__c, X4KG_Dry_Powder_Qty__c, X6KG_Dry_Powder_Qty__c,
                           X9KG_Dry_Powder_Qty__c, X3L_Wet_Chem_Qty__c, X6L_Wet_Chem_Qty__c, X1X1_Fire_blan_Qty__c, X12x12_FB_Qty__c,
                           X12x18_FB_Qty__c, XHose_Reel_19_Qty__c, FA_Travel_Time__c, FA_Job_Time__c, ALUnit_Qty__c,
                           FA_Smoke_Detector_Qty__c, FA_Heat_Detector_Qty__c, FA_Break_Glass_Call_Point_Qty__c,
                           FA_Bell_Sounder_Qty__c, FA_Automatic_Door_qty__c, FA_Central_Station_Link_Qty__c,
                           FA_Remote_Indicator_Qty__c, FA_Beacon_Qty__c, FA_Emergency_Light_Qty__c, FA_Keyswitch_Qty__c,
                           FA_Type_of_Panel__c, Age_of_Panel__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)
{
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;
newsc.X2L_AFFF__c=ssli.X2L_AFFF_Qty__c;
newsc.X3L_AFFF__c=ssli.X3L_AFFF_Qty__c;
newsc.X6L_AFFF__c=ssli.X6L_AFFF_Qty__c;
newsc.X9L_AFFF__c=ssli.X9L_AFFF_Qty__c;
newsc.X2KG_CO2__c=ssli.X2KG_CO2_Qty__c;
newsc.X5KG_CO2__c=ssli.X5KG_CO2_Qty__c;
newsc.X1KG_DRY_POWDER__c=ssli.X1_KG_Dry_Powder_Qty__c;
newsc.X2KG_DRY_POWDER__c=ssli.X2KG_Dry_Powder_Qty__c;
newsc.X4KG_DRY_POWDER__c=ssli.X4KG_Dry_Powder_Qty__c;
newsc.X6KG_DRY_POWDER__c=ssli.X6KG_Dry_Powder_Qty__c;
newsc.X9KG_DRY_POWDER__c=ssli.X9KG_Dry_Powder_Qty__c;
newsc.X3L_WET_CHEMICAL__c=ssli.X3L_Wet_Chem_Qty__c;
newsc.X6L_WET_CHEMICAL__c=ssli.X6L_Wet_Chem_Qty__c;
newsc.X1_x_1m_Fire_Blanket__c=ssli.X1X1_Fire_blan_Qty__c;
newsc.X1_2_x_1_2m_Fire_Blanket__c=ssli.X12x12_FB_Qty__c;
newsc.X1_2_x_1_8m_Fire_Blanket__c=ssli.X12x18_FB_Qty__c;
newsc.Hose_Reel_19mm__c=ssli.XHose_Reel_19_Qty__c;
newsc.Al_Unit__c=ssli.ALUnit_Qty__c;
newsc.Smoke_Detector_Qty__c=ssnewlist.FA_Smoke_Detector_Qty__c;
newsc.Heat_Detector_Qty__c=ssnewlist.FA_Heat_Detector_Qty__c;
newsc.Break_Glass_Call_Point_Qty__c=ssnewlist.FA_Break_Glass_Call_Point_Qty__c;
newsc.Bell_Sounder_Qty__c=ssnewlist.FA_Bell_Sounder_Qty__c;
newsc.Automatic_Door_Qty__c=ssnewlist.FA_Automatic_Door_qty__c;
newsc.Central_Station_Link_Qty__c=ssnewlist.FA_Central_Station_Link_Qty__c;
newsc.Remote_Indicator_Qty__c=ssnewlist.FA_Remote_Indicator_Qty__c;
newsc.Beacon_Qty__c=ssnewlist.FA_Beacon_Qty__c;
newsc.Emergency_Light_Qty__c=ssnewlist.FA_Emergency_Light_Qty__c;
newsc.Keyswitch_Qty__c=ssnewlist.FA_Keyswitch_Qty__c;
newsc.Type_of_Panel_DVR__c=ssnewlist.FA_Type_of_Panel__c;
newsc.Age_of_Panel_DVR__c=ssnewlist.Age_of_Panel__c;
newsc.Job_Time__c=ssnewlist.FA_Job_Time__c;
newsc.Travel_Time__c=ssnewlist.FA_Travel_Time__c;
newsc.Time__c='Minutes';
newsc.Job_time_value__c='Hours';

scnewlist.add(newsc);
}
update scnewlist;

Can any one suggest me what is wrong in my code.

Thanks in advance.

2

Your variable newsc is declared to be a List<SiteContracts__c> but you are using it as if it is a SiteContracts__c.

One way to fix this is to delete the current newsc definition and have your loop like this instead:

for(Engineer_Checklist__c ssli : ssnewList)
{
    SiteContracts__c newsc = new SiteContracts__c();
    newsc.X6L_Water__c = ssli.X6L_Water_Qty__c;
    ...
    scnewlist.add(newsc);
}
update scnewlist;

Or if you can bear the editing, SObjects support named parameters in their constructors so the code can be written like this:

for(Engineer_Checklist__c ssli : ssnewList)
{
    scnewlist.add(new SiteContracts__c(
            X6L_Water__c = ssli.X6L_Water_Qty__c,
            ...
            ));
}
update scnewlist;
  • I did as u said but same Error. – Karti K Oct 13 '14 at 15:50
  • @KartiK I now see that further down you also have starting with this line newsc.Smoke_Detector_Qty__c=ssnewlist.FA_Smoke_Detector_Qty__c; a number of lines where you are referencing ssnewlist - a list - instead of (presumably) ssli - a reference to a single object. Change those. – Keith C Oct 13 '14 at 15:56
  • Now getting this error after editing as u said,- System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] – Karti K Oct 13 '14 at 16:08
  • @KartiK Change update scnewlist; to insert scnewlist;. – Keith C Oct 13 '14 at 16:14
  • Keith again throughing an Error-System.ListException: Before Insert or Upsert list must not have two identically equal elements – Karti K Oct 13 '14 at 16:16
0

Change the List- scnewlist to set.

public set<SiteContracts__c> scnewlist= new set<SiteContracts__c>();
public set<SiteContracts__c> finalscnewlist= new set<SiteContracts__c>();

and use set variable to store the 'newsc'.

finalscnewlist.addall(scnewlist);
insert finalscnewlist;

Thanks, Raviteja

  • Thanks Raviteja, and Kindly can you tel me How to set variable to store the 'newsc'. ? – Karti K Oct 14 '14 at 5:19
  • Take two collection types one is Set type and another list type as below,public set<SiteContracts__c> scnewset= new set<SiteContracts__c>(); public List<SiteContracts__c> finalscnewlist= new List<SiteContracts__c>(); for(){ scnewset.add(newsc); } finalscnewlist.addall(scnewlist); insert finalscnewlist; – Raviteja Oct 14 '14 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.