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
CasselJCasselJ 

Duration and EndDateTime must match.: [DurationInMinutes]

CAN anyone show me the formulat to correctly calculate this field as it does Not auto update when I change the endDatetime field.


 datetime dt = datetime.parse(strDT);
        e.startDateTime =dt; 
        if(e.endDateTime < dt){
            dt = dt.addHours(1);
            e.endDateTime = dt;
            endDate = dt.format('yyyy-MM-dd', 'America/New_York');
            endTime = dt.format('HH:mm', 'America/New_York');
            strEndDatetime = endDate + 'T' + endTime;
            system.debug('#####################################New End Date' + e.endDateTime);
        }else{
            //thisis to insure updating of the duration field
            e.endDateTime = e.endDateTime.addMinutes(15);
            e.endDateTime = e.endDateTime.addMinutes(-15);
         }
SwethaSwetha (Salesforce Developers) 
HI Cassel,
Is the issue happening Salesforce Mobile ? If so, there is currently a known issue that the product team is working to fix. Please see https://trailblazer.salesforce.com/issues_view?id=a1p3A000001HlhWQAS for more details. If it is not a mobile issue, please give more background so I can advise?

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
CasselJCasselJ

Hi Swetha, Thank you for your input. No this is happening in classic. I find it now impoosible to create or edit any event where the datetime fields are changed. 

 How is this field determined?

CasselJCasselJ

Ok I have tried this: It seems to be working in the sandbox;   

if i change the start date i must add a second to teh enddate to trigger the recalculation of the durationinminutes;

Also: BIG Important thing here:  It seems this will ony recalculate if the duration in minutes is null;  so if i set it to null and then change the datatime fields it works.

It has to be set to null prior to each change.

CasselJCasselJ
also have to use datetime.valueof  event though the type is datetime?
datetime dt = datetime.parse(strDT);
e.endDateTime = dateTime.valueOf(dt);
This might have something to do with offsets
CasselJCasselJ
But this still doesnt work in production only the sandbox
 
CasselJCasselJ
I have found this to correct itself by setting the DirationinMinutes to Null prior to changing any date. Then use datetime new instance. and create