NeuroAgent

How to Send Literal Time to Salesforce Time Field from DataWeave

Learn how to send literal time values to Salesforce Time fields from DataWeave without timezone conversion. Fix the issue where Salesforce converts your UTC times based on user timezone settings.

How to send a literal time to a Salesforce Time field from DataWeave without timezone conversion?

I’m using MuleSoft to send data to a Salesforce custom object with a field named Shift_End_Time__c of Time data type. My source system provides this time as a UTC string, for example: “Shift_End_Time__c”: “05:30:00Z”.

The problem:
When I send this value, Salesforce doesn’t store the literal time “05:30”. Instead, it converts it to my user’s local timezone. For example, when I send “05:30:00Z” (5:30 AM GMT), it appears as 11:00 AM in the Salesforce UI for users in the GMT+5:30 timezone.

My goal is for Salesforce to store and display the literal time “05:30:00”, regardless of any user’s timezone settings, as these are shift times that should be timezone-agnostic.

What I’ve tried:
I’ve attempted several DataWeave transformations, but they all result in the same incorrect conversion:

  1. Casting as Time:
Shift_End_Time__c: item.ShiftEndTime as Time
  1. Casting as LocalTime (to strip timezone):
Shift_End_Time__c: (item.ShiftEndTime as LocalTime)

The Salesforce field is defined as Time type (not DateTime or Text). I need the time to appear consistently across all users regardless of their timezone settings.

NeuroAgent

When sending a literal time to a Salesforce Time field from DataWeave, you need to properly format the time without timezone information. The issue occurs because Salesforce interprets the “Z” suffix as UTC timezone and converts it based on the user’s timezone settings. To store “05:30” literally without conversion, you should send it as a simple time string without timezone indicators, using DataWeave’s Time type formatting.

Contents

Understanding Salesforce Time Field Behavior

Salesforce Time fields are designed to store literal time values without timezone conversion, unlike DateTime fields which are stored in UTC and converted for display. However, the conversion behavior you’re experiencing suggests that the “Z” suffix in your input string is being interpreted as timezone information by the Salesforce API.

According to Salesforce Stack Exchange, Time fields in Salesforce “are not converted to a timezone” and should maintain their literal value. The issue likely stems from how the DataWeave transformation processes the input before sending it to Salesforce.

Root Cause of the Timezone Conversion Issue

The problem occurs because your input contains the “Z” timezone indicator (UTC), which tells Salesforce to interpret this as a UTC time. When the Salesforce UI displays this time, it converts it based on the current user’s timezone settings.

For example:

  • Input: “05:30:00Z” (5:30 AM UTC)
  • User in GMT+5:30 sees: 11:00 AM
  • User in GMT-5 sees: 12:30 AM previous day

The solution is to remove the timezone information entirely before sending the data to Salesforce.

Correct DataWeave Transformations

Method 1: Direct Time Type Conversion

The most straightforward approach is to convert the string to a Time type in DataWeave, which will automatically strip timezone information:

dw
%dw 2.0
output application/json
---
{
  "Shift_End_Time__c": "05:30:00Z" as Time { format: "HH:mm:ss" }
}

This will convert “05:30:00Z” to a Time object that Salesforce can interpret as a literal time without timezone conversion.

Method 2: String Manipulation

You can also manipulate the string directly to remove the “Z” indicator:

dw
%dw 2.0
output application/json
---
{
  "Shift_End_Time__c": replace("05:30:00Z", "Z$", "") as Time
}

Or more robustly:

dw
%dw 2.0
output application/json
---
{
  "Shift_End_Time__c": replace(item.ShiftEndTime, "Z$", "") as Time { format: "HH:mm:ss" }
}

Method 3: Using LocalTime with Proper Formatting

Another approach is to use LocalTime, which is timezone-agnostic:

dw
%dw 2.0
output application/json
---
{
  "Shift_End_Time__c": "05:30:00Z" as :localtime { format: "HH:mm:ss" }
}

Or for your specific use case with the input field:

dw
%dw 2.0
output application/json
---
{
  "Shift_End_Time__c": (item.ShiftEndTime as Time { format: "HH:mm:ss" })
}

Salesforce API Requirements for Time Fields

According to the Salesforce Stack Exchange documentation, Time fields should be formatted as simple time strings without timezone information. The format “HH:mm:ss” is typically acceptable.

When using the Salesforce API, Time fields expect:

  • No timezone indicators (no “Z”, “+05:30”, etc.)
  • Standard 24-hour format (HH:mm:ss)
  • No date components

Testing and Validation

To ensure your transformation works correctly:

  1. Test in DataWeave Console: First test your DataWeave transformation in the MuleSoft DataWeave console to verify the output format.

  2. Use Salesforce API Explorer: Test the payload directly using Salesforce’s API explorer to confirm the field accepts the format.

  3. Verify Storage: After sending the data, check the database directly using Salesforce Workbench to ensure the time is stored as you expect.

  4. Test with Different Timezones: Have users with different timezone settings verify that the time displays consistently as “05:30”.

Best Practices

  1. Input Validation: Always validate that your source system provides time in a consistent format before processing.

  2. Error Handling: Add error handling for invalid time formats:

dw
%dw 2.0
output application/json
---
{
  "Shift_End_Time__c": (item.ShiftEndTime match {
    case /.*Z$/ -> replace(item.ShiftEndTime, "Z$", "") as Time { format: "HH:mm:ss" }
    case _ -> item.ShiftEndTime as Time { format: "HH:mm:ss" }
  })
}
  1. Documentation: Document your transformation approach so other developers understand why you’re using specific DataWeave functions.

  2. Consistency: Apply the same transformation consistently across all integrations that interact with this Salesforce field.

  3. Monitoring: Monitor for any timezone-related issues in your integration logs, as these can be difficult to debug after deployment.


Sources

  1. How to send a literal time to a Salesforce Time field from DataWeave without timezone conversion? - Stack Overflow
  2. What is the correct format in mulesoft to update a date datatype field in salesforce through upsert API - Salesforce Stack Exchange
  3. Salesforce displaying Time custom field in GMT instead of User’s timezone - Salesforce Stack Exchange
  4. Date formatting in DataWeave 2.0 - Caelius Consulting
  5. Format Dates and Times | MuleSoft Documentation
  6. Change a Time Zone | MuleSoft Documentation

Conclusion

To successfully send literal time values to Salesforce Time fields from DataWeave without timezone conversion:

  • Remove timezone indicators (like “Z”) before sending to Salesforce
  • Use DataWeave Time type with proper formatting (HH:mm:ss)
  • Test thoroughly with different timezone settings
  • Document your approach for future maintenance

The key insight is that Salesforce Time fields should receive simple time strings without any timezone information. By properly formatting your DataWeave output to strip timezone data, you’ll ensure that “05:30” remains “05:30” for all users, regardless of their individual timezone settings.