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
cmarkcmark 

setting datetime field to "now"...

I want to update a record and set the value of a custom DateTime field to the current date and time (SFDC system date and time).  So the equivalent of updating a field in Oracle and passing "now()" as the value.  Is there a one-step way to do this?  Or do I have to query the timestamp and the put it into the record that I'm updating?

Thanks
Chris
dotnetericdotneteric
I would also like to do the same thing.  Please help.
caroline_sfdccaroline_sfdc
Hi Chris,

You can do this with a workflow rule that updates your custom DateTime field whenever the record is updated or created. Just make the workflow field update change the value of your field to a formula defined as:

NOW()

It's not quite one step since you need to define the custom field and the workflow rule/action, but it doesn't take very long to set up -- I just did it myself in less than 5 minutes.

If you haven't used workflow rules before, take a look at Chapter 8 of the free e-book, "Creating On-Demand Applications," available at http://wiki.apexdevnet.com/index.php/Creating_On-Demand_Applications:_An_Introduction_to_the_Force.com_Platform.
It should give you a good overview.

Hope this helps,

Caroline Roth
Co-Author, "Creating On-Demand Applications"


dotnetericdotneteric
Let me explain my requirement:  I need to write the current datetime to an opportunity when a web service call done within an s-control is successful.  It cannot be the current datetime whenever the opportunity is created or modified.  I've resorted to setting it to javascript's new Date() value until I find a more reliable way.  We have a lot of opportunity custom fields in our SFDC instance, so I would like a solution that will not require an additional field to be created. 

Is it possible to send a dummy datetime as the value for the field and have the field defined as type formula that sets the field to NOW() if the new field value is not null?
cmarkcmark
Thanks for the response, but my requirement is similar to dotneteric's.  Whether or not I update that timestamp is conditional on a couple of other things.  So it's not as simple as setting it to the value of the system modstamp.

Thanks
Chris
Jeff TalbotJeff Talbot

Appending to what Caroline said, workflow can have conditions... it doesn't have to trigger at every create or update. Additionally, default values can be defined by conditions in a formula. It's not really clear to me why your requirement can't be met with Workflow and formulas. Can you expand on your requirements? Also, explain what you've tried, the result, and why it didn't meet your requirments.

cmarkcmark
Thanks for the response.  Of course this can be handled with workflow etc.  I can also do it manually in my code.  My question is simply whether there is something in the API that will let me do it without workflow or additional code. 
Thanks
chris