0

How to update duration field when we update Start time and Time of event using inline edit? Note:- I am editing only Start date and End date using inline edit.

my requirement is like I want the start and end DateTime as inline editable in my table for the user. So the issue is like how to calculate again Duration..? Is it one time or updatable? Ok, and if change it in your customized table it's showing error while the update for DurationInMinutes...

0

You don't have to update the DurationInMinutes field if you're also updating the EndDateTime field. The system will populate it or update it automatically.

You just can't populate both unless the values match (i.e., the DurationInMinutes value is actually the difference in minutes between StartDateTime and EndDateTime).

From the Event SOAP Reference:

In versions 13.0 and later, this field (DurationInMinutes) is optional, depending on the following:

If IsAllDayEvent is true, you can supply a value for either DurationInMinutes or EndDateTime. Supplying values in both fields is allowed if the values add up to the same amount of time. If both fields are null, the duration defaults to one day.

If IsAllDayEvent is false, a value must be supplied for either DurationInMinutes or EndDateTime. Supplying values in both fields is allowed if the values add up to the same amount of time.

If you are making updates to an Event, you can either

  • Not populate (not query) the DurationInMinutes field, in which case the system will autopopulate it;
  • Null out the DurationInMinutes field (same result);
  • Calculate the update to DurationInMinutes yourself.

Note that

Event e = [SELECT StartDateTime, EndDateTime, DurationInMinutes FROM Event LIMIT 1];

e.EndDateTime = e.EndDateTime.addMinutes(1);
update e;

results in an error, because we populate but do not update DurationInMinutes.

This works fine, because we don't query DurationInMinutes:

Event e = [SELECT StartDateTime, EndDateTime FROM Event LIMIT 1];
e.EndDateTime = e.EndDateTime.addMinutes(1);
update e;

as does this, where we set the field to null:

Event e = [SELECT StartDateTime, EndDateTime, DurationInMinutes FROM Event LIMIT 1];

e.EndDateTime = e.EndDateTime.addMinutes(1);
e.DurationInMInutes = null;

update e;

and this also works fine, because we update the field manually.

Event e = [SELECT StartDateTime, EndDateTime, DurationInMinutes FROM Event LIMIT 1];
e.EndDateTime = e.EndDateTime.addMinutes(1);
e.DurationInMinutes += 1;
update e;

So the upshot is you have no need to calculate the field yourself. Just don't query it in the first place, if you're not using it, or set it to null at the time you perform the update DML operation and the system will calculate it for you.

  • I have created list format in vf to show events and now i want to calculate duration when user changes StartTime and EndTime while update.... – optimistic_cloud Aug 30 '18 at 9:23
  • Hi @PranavJoshi, if you don't feel that my answer covers your question, would you please edit your question to clarify by including your code and describing why and how you are calculating the event duration? As I note above, the system will do this for you. – David Reed Aug 30 '18 at 10:58
  • OK David my requirement is like I want start and end DateTime of is inline editable in my table. So the issue is like how to calculate again Duration its one time or updatable? – optimistic_cloud Sep 1 '18 at 8:09
  • I have updated my answer to try to clarify. – David Reed Sep 1 '18 at 13:00

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.