1

I have created several custom fields for our Accounts in Salesforce. One is called "Date and Time Latest Login". Each Account also has an ID (in Salesforce) and an "External ID" which references our company-internal user ids.

Now, what I want to do is to update the field "Date and Time Latest Login" for the user with the "External ID" xyz with the current timestamp through the Developer Force Client for .NET. I know that Salesforce has a function called now() to insert the current timestamp into a field, but I don't know how to call it or trigger it's execution through the API.

Therefore, I would like to know:

  • How can I populate or better yet update a timestamp field for a given entry with the current timestamp (without generating a timestamp in C# first and then pass that encapsulated in a JSON object)?

  • How can I update the entry for the user with the "External ID" "abc"? All examples I found so far create a new entry and then use the reference they get from that Create-Query and inject it into the update call (e.g. https://github.com/developerforce/Force.com-Toolkit-for-NET#update). How can I update an entry that already exists as an Account by supplying our "External ID" as the key?

1

How can I populate or better yet update a timestamp field for a given entry with the current timestamp?

One option is to use an Account trigger as @crmprogdev suggested. My take on that is that the Account trigger always updates the "Date and Time Latest Login" field. That way it doesn't matter what you try and set that field to. If the trigger detects it is changing it sets that value to the current date time.

You would likely need some recursion protection here to stop the same Account being processed multiple times.

You could also use a workflow field update to similar effect.

Another option it to provide a custom Apex web service to set the field. You then call the web service whenever you what the value updated.

But why not just pass the value in from .NET? You could easily send in the DateTime.UtcNow value to set the field. Seems like the value would be accurate enough as whatever you do there is going to be some variation in exact timing due to the web request.

How can I update the entry for the user with the "External ID" "abc"?

This is what the Upsert API call is designed for. With an upsert you can can provide the external ID and Salesforce will do an update if an Account with the matching ID is found. Otherwise it will perform an insert.

See Insert or Update (Upsert) a Record Using an External ID

1

Obviously, you're going to need the trigger written in Apex to update the Account based on the related Child object of Contact. If the Contact has an External ID, that can be used to reference the Contact to trigger the update on Account provided you add a field to the Contact which updates then updates it's related Account when you use web services to update the custom field with the new time stamp. That's the general approach you'll want to take.

You could use the timestamp from whatever source you wanted to, either your web service, external service or even the trigger itself by using a checkbox that tells the trigger to update the timestamp on the related account, then resets the checkbox to false at the end of its logic.

Beyond that, your question is far too broad to answer in our format here on SF.SE.

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.