4

I'm getting the following error in the following method:

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

method:

private Order_Activity__c createOrderActivity(string salesOrderId, string ownerId, string locationId, string recordtypeId, string activity, string status, string separation, string screen,
                                                        string ink, string workCenterId, datetime startTime) {
    Order_Activity__c oa = new Order_Activity__c();
    oa.Sales_Order__c = salesOrderId;
    oa.Sales_Order_Owner__c = ownerId;
    oa.Location_Number__c = locationId;
    oa.RecordTypeId = recordtypeId;
    oa.Activity__c = activity;
    oa.Activity_Status__c = status;
    oa.Separation_Status__c = separation;
    oa.Screen_Status__c = screen;
    oa.Ink_Status__c = ink;
    oa.Work_Center__c = workCenterId;
    DateTime dt = startTime;
    oa.Start_Time__c = DateTime.newInstance(dt.Start_Time__c.yearGmt(), dt.Start_Time__c.monthGmt(), dt.Start_Time__c.dayGmt(), 12, 0, 0);
    return oa;
}

The error occurs on this line:

    oa.Start_Time__c = DateTime.newInstance(dt.Start_Time__c.yearGmt(), dt.Start_Time__c.monthGmt(), dt.Start_Time__c.dayGmt(), 12, 0, 0);

Thanks for any help.

  • 1
    Can you debug dt value ? also , I think you don't need to assign startTime . Try this oa.Start_Time__c = DateTime.newInstance(dt.yearGmt(), dt.monthGmt(), dt.dayGmt(), 12, 0, 0); – amidstCloud Apr 30 '15 at 20:17
  • 7
    I don't think you mean dt.Start_Time__c. I think you mean just dt – Jeremy Nottingham Apr 30 '15 at 21:01
  • Thank you Jeremy!! I needed another set of eyes on that one! Thank you! – Dman100 Apr 30 '15 at 21:25
  • @JeremyNottingham. Please post your comment as an answer to the question. Otherwise, it leaves the impression to anyone who searches the topic later that the question didn't receive an answer. Dman100 will then be able to mark his question as solved by clicking the checkmark beside your answer. Thank you. – crmprogdev May 1 '15 at 17:23
0

Props to @amidstCloud, who basically gave the same comment as me.

The variable dt is a DateTime, and that's what you want to be evaluating. A DateTime has no fields or attributes; it should just be used directly. I would guess that the reference to Start_Time__c was left over from a previous version of your code.

oa.Start_Time__c = DateTime.newInstance(dt.yearGmt(), dt.monthGmt(), dt.dayGmt(), 12, 0, 0);

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.