I am trying to push leads into Salesforce and I am passing in the following value...


This format appears to match the YYYY-MM-DDTHH:MM:SSZ format listed in the documentation. When I check the lead, it successfully pushed into Salesforce but the field Requested_Appointment_DateTime is still null. Any ideas?

Edit: I tried some execute anonymous tests to see if I could assign the date as shown... but it's saying invalid date/time. This matches the docs though?!

Lead l = [Select id, Requested_Appointment_DateTime__c from Lead where id='00Q3o00001AuWTOEA3'];
l.Requested_Appointment_DateTime__c = DateTime.parse('2021-12-14T18:27:33Z');

When I try to set the time to system.now() it returns something that looks like '2021-12-14 18:27:33' with no T or Z... when I try and parse that string it says invalid date. What is the correct date format??

1 Answer 1


If you were expecting the lead record to display the new value, you forgot the step where you save the data back to the database.

Lead l = [Select id, Requested_Appointment_DateTime__c from Lead where id='00Q3o00001AuWTOEA3'];
l.Requested_Appointment_DateTime__c = DateTime.valueOfGmt('2021-12-14 18:27:33');
update l;
  • No, I was expecting the value to assign correctly. It throws an error saying it could not parse this date format. This apex code is just for demonstration that the field isn't setting via api call. I'm sure the format is right... that's what's on the docs and in all the questions I looked at. Am I missing something obvious here? The error is System.TypeException: Invalid date/time: 2021-12-14 18:27:33
    – PaulyP
    Oct 6, 2021 at 3:53
  • 1
    @PaulyP For API calls, you use the specific format you found in the docs. This is the ISO8601 date time format supported by Salesforce. Using DateTime.valueOf or DateTime.parse requires a different format. I've edited this answer to reflect the correct format. If the value is null, there may be another reason, either an automation or code that is clearing out the field mid-transaction.
    – sfdcfox
    Oct 6, 2021 at 4:16
  • Have you tried Datetime.valueOf ? Yes, what Sfdcfox said Oct 6, 2021 at 4:17
  • @sfdcfox When I submit using the ISO8601 format it does not populate. This is a new field so no existing automations would update it. Would it matter that this is a web-to-lead submission?
    – PaulyP
    Oct 6, 2021 at 4:45
  • @PaulyP Yes, web-to-lead expects it to be in a locale-dependent format. Try "mm/dd/yyyy hh:mm aa", such as 12/14/2021 6:27 pm
    – sfdcfox
    Oct 6, 2021 at 5:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .