+ Start a Discussion
Sylvio AvillaSylvio Avilla 

Initial term of field expression must be a concrete SObject: Id - Retreive Value from Field, based on ID

Hello,
I'm trying to solve a problem for a few days now and decided to ask for help, once again ... :S
Here is part of my code.
Basically I got a list:
List<CustomObject__c> lstMyObjects =  [Select ID, Name, DateTime1__c,DateTime2__c
                                     from CustomObject__c ];
Found the difference between all DateTime and Sorted It:
for(Integer i=0; i<lstMyObjects.size();i++){
            
           Long myValue = 0; 
          	
                Long dt1Long = (lstMyObjects[i+1].Field1__c.getTime())/1000;
                Long dt2Long = (lstMyObjects[i].Field2__c.getTime())/1000;
                myValue = (dt1Long-dt2Long)/60;
              	idDt1.put(myValue,lstMyObjects[i+1].ID);
              	idDt2.put(myValue,lstMyObjects[i].ID);

}

            myValues.add(myValue);
            (myValues.sort());
Now I've got the second greatest difference between DateTime value
Got the record ID
Now is the problem. For some reason, cannot find a way to retrieve the DateTime1__c value, using the ID, and receive the following error

"Initial term of field expression must be a concrete SObject: Id"


 
Id test = idDt1.get(myValues[myValues.size()-2]);
long time = test.DateTime1__c.getTime()/1000;

}
Don't know if it was clear enough, but hope someone could help me!

Thanks


 
Amit Singh 1Amit Singh 1
Hello,

Correct me if I am wrong. You are getting the error on below line. The error is because you are putting Id as the value in Map and then trying to access custom field of that Object using Id. If you are accessing any field then it must be Object. Like lstMyObjects[i+1].Field1__c.getTime()
long time = test.DateTime1__c.getTime()/1000;

If yes then use below code.
for(Integer i=0; i<lstMyObjects.size();i++){
            
           Long myValue = 0; 
          	
                Long dt1Long = (lstMyObjects[i+1].Field1__c.getTime())/1000;
                Long dt2Long = (lstMyObjects[i].Field2__c.getTime())/1000;
                myValue = (dt1Long-dt2Long)/60;
              	idDt1.put(myValue,lstMyObjects[i+1].DateTime1__c);
              	idDt2.put(myValue,lstMyObjects[i].DateTime2__c);

}

            myValues.add(myValue);
            (myValues.sort());
 
DateTime test = idDt1.get(myValues[myValues.size()-2]);
long time = test.DateTime1__c.getTime()/1000;

}
Let me know if this helps :)

Thanks!
Amit
 
Naval Sharma4Naval Sharma4
Here is the problem.
Id test = idDt1.get(myValues[myValues.size()-2]);
long time = test.DateTime1__c.getTime()/1000;

test variable is declared as Id and you are trying to get the DateTime1__c which can not be found on Id object.