function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Praetorian65Praetorian65 

Error: Compile Error: Initial term of field expression must be a concrete SObject

Error: Compile Error: Initial term of field expression must be a concrete SObject: Datetime at line 53 column 61
 
Apex is driving me up the wall. I am trying to convert from a datetime to a date. Line 53 is in bold. It will not let me use licenseArray[i].StartDate to access the date (licenseArray is an array of License objects). I have successfully used licenseArray[i].StartDate in the creation of a custom object (License__c) but I need to change this object to have Date fields instead of DateTime. I am getting the data from a webservice which provides DateTime. StartDate and EndDate can both be null. How can I fix this?
 
Code:
        try{
            While(licenseArray.Size() > 0)
            {               
                for(Integer i = 0; i < licenseArray.Size(); i++)
                {
                    date endD;
                    date startD;
                    
                    if(licenseArray[i].StartDate != null)
                    {
                        //DateTime startDateTime = licenseArray[i].StartDate;
                        Integer startYear = licenseArray[i].startDate.Year;
                        Integer startMonth = licenseArray[i].startDate.Month;
                        Integer startDay = licenseArray[i].startDate.Day;
                        startD = date.newinstance(startYear,startMonth,startDay);
                    }
                    if(licenseArray[i].EndDate != null)
                    {
                        DateTime endDateTime = licenseArray[i].EndDate;
                        Integer endYear = endDateTime.Year;
                        Integer endMonth = endDateTime.Month;
                        Integer endDay = endDateTime.Day;
                        endD = date.newinstance(endYear,endMonth,endDay);
                    }
                                   
                    
                    License__c newLicense = new License__c(ContactName__c = licenseArray[i].ContactName, NetworkCode__c = licenseArray[i].NetworkCode, Period__c = licenseArray[i].Period,
                                            Number__c = licenseArray[i].Number_x, EndDate__c = endD, StartDate__c = startD);
                                            
                                            
                    myList.Add(newLicense);
                    if(myList.Size() == 1000)
                    {
                        myListList.Add(myList);
                        myList = new List<License__c>();
                    }
                    
                }   
                index = index + count;
                licenses = data.GetLicenseData(index,count);
                licenseArray = licenses.License;
            }
            
        } catch (Exception ex)
        {
            
        } 

 
JeremyKraybillJeremyKraybill
The DateTime's year / month / etc methods are instance methods, not fields, so you need to do
Code:
Integer startYear = licenseArray[i].startDate.year();

 
That should work. It is a little frustrating that Date doesn't have a getTime() method to convert to ms, which would definitely help Date/DateTime interoperability. Hope that helps.

Jeremy Kraybill
Austin, TX
JeremyKraybillJeremyKraybill
Also I realized that you have "__c" in your later reference to StartDate, but not in the line you provided, so that may be an issue too.

Jeremy Kraybill
Austin, TX
Praetorian65Praetorian65
Thanks. Its a pitty that error message couldnt be more helpful.