1

Here is my requirement.

  • User A can do a check in (through click of a button) which creates a record in custom object "CheckIn__c" and the following fields will be populated: [CheckInTime__c] - current time [Duration__c] - duration in minutes [Supervisor__c] - user will select the supervisor user in this field.
  • There is a formula field [ScheduledCheckOutTime__c] which is [CheckInTime__c + Duration__c].
  • User A can check out using another button which will populate the [CheckOutTime__c] field.
  • If user forgets to checkout before the [ScheduledCheckOutTime__c] then an SMS should be sent to the Supervisor twice - (1). 5 mins after ScheduledOutTime, (2). 20 mins after ScheduledCheckOutTime.
  • User A can extend the check in by adding more minutes to the Duration field which will automatically extend the [ScheduledCheckOutTime__c].

The challenge is what is the best way to implement the SMS functionality. We tried the following options:

  • Batch Apex which runs every 15 mins to see if there is an expired check in and sends SMS. Cons: We could NOT achieve the 5 mins & 20 mins timeline exactly.
  • Time Based Workflow: this approach works fine only when the interval is more than 1 hour from any date time field. We are dealing with minutes here.

As of now, the only option we have is to reduce the batch job interval to 5 minutes.

Can anyone think of another way to implement this?

2

There is a hack somewhere on the Internet that sets the date field (maybe a copy of the actual field) to 55 min before the actual time so that the time trigger works in the next 5 min. However, that hack may not be exactly what you want.

From your use case, it seems that the date/time fields may be used in business-critical functions (billing, establishing trust/accountability?). Salesforce time triggers may not be reliable to the minute and satisfy your requirements in all cases. Salesforce will execute trigger any time within 15 min after the trigger time. Refer: https://help.salesforce.com/articleView?id=000231089&type=1

What I would probably do is to negotiate with the business for a 15 min reminder and use the hack (ugly but works). The actual entry of time is assured to the end clients within the hour and not in minutes.

If the reminder is non-negotiable, I would initiate a transaction to an external system upon check-in and check-out, and control SMS reminders external to Salesforce.

A batch running every 5 min (assuming that the scheduled batch * can * start in 5 min) will work too. But I would rather not have index/full scan type queries hitting the system every 5 min. And, limits.

  • Indexed queries aren't that expensive. It should have acceptable performance. – sfdcfox May 6 at 2:11
  • 1
    I went with SMS platform doing the scheduling in a similar scenario. Even though e.g. Schedulable interface promises cron-like semantics, there's no guarantee that it executes on time. – identigral May 6 at 2:35
  • @identigral Was the delay due to the inherent difficulties in SMS systems & deliverability delays? But yes, I do understand what you have indicated here - scheduling will not be 'on time' in either case. – Prashanth K May 6 at 10:54
  • @PrashanthK SMS platform worked just fine, no delay there. We scheduled messages to fire at a future date/time and never saw any issues. With SF on the other hand, it was almost impossible to achieve for all the usual "subject to availability" reasons. – identigral May 6 at 14:43
  • 1
    Thanks much Prashanth. As of now, we are proceeding with the 5 mins batch job and the query has specific criteria. Long term, we will think about moving the SMS logic outside of Salesforce. – wesfaith May 13 at 22:37

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.